Forum Moderators: coopster
<div id="content">
<?php
switch($page)
{
default: include('home.inc');
break; case "home": include('home.inc');
break; case "podcast": include('podcast.inc');
break; case "photos": include('photos.inc');
break; case "id": include('id.inc');
break; case "friends": include('friends.inc');
}
?>
</div>
<div id="links>
<a href="home.php?page=home">home</a>
<a href="home.php?page=podcast">podcast</a>
<a href="home.php?page=photos">photos</a>
<a href="etc..."
</div>
However, ive been reading the register_globals ON setting is a compromise to security. so i turned it off. needless to say the above script doesnt work anymore...
-Then i found this script:
<div id="content">
<?php
$load = array ('home','podcast','photos','id','friends');
$page = $_GET['$page'];
if (isset (in_array ($page, $load) ))
{
require "$page.inc";
}
else
{
require "home.inc";
}
?>
</div>
<div id="links>
<a href="home.php?page=home">home</a>
<a href="home.php?page=podcast">podcast</a>
<a href="home.php?page=photos">photos</a>
<a href="etc..."
</div>
-This one LOOKED like it should work. it declares the variables beforehand, to adhere to the register_globals setting being off. but it doesnt work at all? i have no clue whats wrong with it. when i access the page via http, the html source code shows up blank?
ANY help or suggestions would help alot! thanks!
also, going through the script, is the logic valid? maybe cuz im using php5 it wont work? i dunno...
also #2, is there a way to turn register_globals on, just for this site and this site only (leaving any other sites on the server unaffected: register_globals still off)? all im using php for is: navigation, email, and a shoutbox... would it still be a threat to security?
the second script was just horrible from the get-go.. i dont know exactly what it was (im new to php) but i figured it had something to do with the "if (isset ( etc. " part. although they made perfect sense to me.
i tried fixing it too many times, then gave up. so i went back to the first script which worked (the one that was valid with register_globals ON). im using php5 and which im sure most of you's know... register_globals is OFF by default. So, not declaring your variables first is a no-no.
What i did was sooo elementary.. i feel dumb for not thinking to do it in the first place. heres how i changed the script:
_ORIGINAL______________________
<div id="content">
<?php
switch($page)
{
default: include('home.inc');
break; case "home": include('home.inc');
break; case "podcast": include('podcast.inc');
break; case "photos": include('photos.inc');
break; case "id": include('id.inc');
break; case "friends": include('friends.inc');
}
?>
</div>
<div id="links">
<a href="home.php?page=home">home</a>
<a href="home.php?page=podcast">podcast</a>
<a href="home.php?page=photos">photos</a>
<a href="etc..."
</div>
_REVISED_______________________
<div id="content">
<?php// all i had to do was declare my globals...
$load = array ('home','podcast','photos','id','friends');
$page = $_GET['page'];
// Im retarted, i know
switch($page)
{
default: include('home.inc'); break;
case "home": include('home.inc'); break;
case "podcast": include('podcast.inc');break;
case "photos": include('photos.inc'); break;
case "id": include('id.inc'); break;
case "friends": include('friends.inc'); break;
}
?>
</div>
<div id="links">
<a href="home.php?page=home">home</a>
<a href="home.php?page=podcast">podcast</a>
<a href="home.php?page=photos">photos</a>
<a href="etc..."
</div>
so yeah. i wasted too much time looking for extra resources to copy from.. until i finally decided to take a crack at it myself. low and behold... amazing. i feel amazing.
just a thought.. the second script i tried i actually liked alot better. it was much more leaner. can anyone pinpoint what was wrong with the logic? im almost certain its the if (isset (in_array ($page, $load) )) condition/statement/whatever..?
as far as error reporting, i attempted using henry0's suggestion and placed '<?php error_reporting (E_ALL);?>' in my document. however, it didnt output any errors? then i thought im probably putting it in the wrong spot, so i tried using it in several locations: before the <html> tag, after the <html> tag, in the <head> section, and in the <body> section.... nothin-
now im thinking at this point, could this be a configuration issue?
heres a look at the script again:
<?php
$load = array ('home','podcast','photos','id','friends');
$page = $_GET['page'];
if (in_array('$page', '$load'))
{
require "$page.inc";
}
else
{
require "home.inc";
}
?>
thanks guys