![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
|
Stupid Problem....
Ok, I have this code
<?php
if( $content == NULL )
{
include(home . ".php");
}
else
{
$content = $_GET["content"];
include($content . ".php");
}
?>when coupled with... <a href="index.php?content=about">About</a> it's suppose to link the "about.php" page, to the table cell on the site. It was working before... for the longest time actually. Suddenly and Randomly it isn't anymore. Any Ideas? Thanks
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former. |
|
|
|
|
|
#2 |
|
Newbie
|
Did you recently upgrade your PHP?
EDIT: Just add "extract($_GET);" before the if statement. It will work. ![]()
__________________
I wish I was you, so I could be friends with me. |
|
|
|
|
|
#3 |
|
Programmer
|
nope, I am using a WAMP server to test it, it worked(or did before today anyway) there.
And the site that it is being tested in is showing PHP: 4.4.0-3.rhel3.art (/usr/bin/php) as the version.
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
check your php.ini for registered globals property. try changing. your $content value depends on whether or not the globals is turned on or off. that's probably why. it would also explain why it stopped working (thats if it changed).
|
|
|
|
|
|
#5 | |
|
Newbie
|
Quote:
Doubt it. Re-look at his if statement. He says if $content is null (which it always will be since he didn't extract the Get variables) then include home.php. He never enters the else part of the if statement, since the first part is always true. It has nothing to do with the php.ini file.
__________________
I wish I was you, so I could be friends with me. |
|
|
|
|
|
|
#6 |
|
Newbie
|
Read my post above...
Use "extract($_GET);" before your if statement. This will extract all GET variables. The reason for this is simple. If you don't extract the $content variable before the statement, it is always going to be null because you haven't assigned it any value, and hence why it never enters the else part of your if statement. Just a bit of a logic error really. :p Your updated code should look like this: <?php
extract($_GET); //extracts the $content variable
if( $content == NULL )
{
include(home . ".php");
}
else
{
include($content . ".php");
}
?>
__________________
I wish I was you, so I could be friends with me. |
|
|
|
|
|
#7 | |
|
Programmer
|
Quote:
That works, thanks alot!
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former. |
|
|
|
|
|
|
#8 |
|
Expert Programmer
|
Yeah, It was just along shot. If it was working earlier, then it wasn't likely. Plus he didn't upgrade php either. Just a suggestion, figured it shouldn't be overlooked.
|
|
|
|
|
|
#9 |
|
Programmer
|
so why did you use
include(home . ".php"); like that not like that include("home.php"); |
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Using the extract function or turning on the register_globals setting is generally considered bad practice, as not conforming to strict PHP standards can result in loopholes and security flaws. Of course, the same could happen even without using these, but it's much less likely. I would personally do it like this:
[php]$content = isset($_GET['content']) ? $_GET['content'] : null; if ($content) { include($content . '.php'); } else { include('home.php'); }[/php] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|