[PHP] Not Really sure whats its called.
Hi, i know this might sound stupid, but i know basic html, and css, and i started designing a site for my server a few days ago. Awhile back i got a PHP code where I could just put the code on one page and then just use index.php?go=name to go to a different page. And it worked before (like 2 years ago) and now, when i put the right page, i see the page thats supposed to be there (mainpage.php) but when i go to index.php?go=connect instead of seeing the connect page, i see the home page still. Is there something wrong with my coding? or does this code not work anymore? (or whats this even called :P)
Thanks Again, and again, sorry if the answer is simple, i just have been trying for two days now.
Code:
<?php error_reporting (E_ALL ^ E_NOTICE);
if(!$go){ $go = $HTTP_GET_VARS['go']; }
if($go=="" or $go=="home"){
include("mainpage.php");
}elseif($go=="connect"){
include("connect.php");
}
?>
Re: [PHP] Not Really sure whats its called.
lol?
just use $_GET.
$_GET are much more simple and doesnt require an else.
ITs like post only the data is shown on the link.
Re: [PHP] Not Really sure whats its called.
LOL i had this problem, weeks ago. No one really helped.
if(isset($_GET['web])){
$web=$_GET['web'];
if($web=="Home"){
echo" HOme";
}
elseif($web=="LOSER"){
echo" No ur the loser";
}
else{
echo"Webpage not found";
}
?>
Re: [PHP] Not Really sure whats its called.
@Hidden: You are missing a ' after the first word 'web' also the '==' operator is case sensitive ( i quite sure of it ) so home is not Home neither HOme etc.
@Desmus: I suggest leaving error_reporting(E_ALL) for testing, as andres said $_GET looks more clear. I'm not sure of what the !$go do, if you wanted to test if it's empty or set, use the functions empty(), isset()
Re: [PHP] Not Really sure whats its called.
little bumb.. i think it was:
PHP Code:
<?php
web = $_GET['name']; //get name from url
web = strtolower($web); //string to lower characters otherwise Home will result in the error page
if ($web=="home") {
'executeble code for home' // put your code here for home
}
elseif ($web=="otherthingy") {
'code for otherthingy' //here for other thing
}
// for more pages put another elseif here
else {
include(404.php) // obviously your 404
}
?>
Re: [PHP] Not Really sure whats its called.
Yep, $HTTP_GET_VARS is deprecated, so use $_GET instead ;)
PHP Code:
<?php
if (!$_GET['go'] || $_GET['go'] == 'home')
{
include('mainpage.php');
}
else if ($_GET['go'] == 'connect')
{
include('connect.php');
}
?>
Or even better for possible future expansions:
PHP Code:
<?php
$pages = array('home' => 'mainpage.php', 'connect' => 'connect.php');
if (array_key_exists($_GET['go'], $pages))
{
include($pages[$_GET['go']]);
}
else
{
include('mainpage.php');
}
?>
@G_NETWORK, your code syntax isn't correct for variables
Re: [PHP] Not Really sure whats its called.
It would work, but you'd need register_globals on. Two years ago this was quite common, but since it is a MAJOR security risk these days it is usually turned off - and rightfully so.
Daevius' method is quite elegant, though it is a tad bit superflous. Easier would be:
PHP Code:
$allowedPages = array('home', 'contact', 'info');
if ($allowedPages[$_GET['go']])
include ($_GET['go'] . '.php');
Mind, if you are running linux and have 2 pages, one called home.php that is user accesable and one called Home.php that is not, this is in principle a security risk. Since in that case your code has been written by a lunatic monkey, I wouldn't worry much about it :wink:
Re: [PHP] Not Really sure whats its called.
Well, i just started out learning php so yeah my code could be wrong :p but atleast i tried :P
And it worked on my webhost so... :P