Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 10th, 2006, 1:56 PM   #1
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
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.
drifter is offline   Reply With Quote
Old Apr 10th, 2006, 2:17 PM   #2
mongeau
Newbie
 
mongeau's Avatar
 
Join Date: Apr 2006
Location: Fargo, ND
Posts: 29
Rep Power: 0 mongeau is on a distinguished road
Send a message via MSN to mongeau
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.
mongeau is offline   Reply With Quote
Old Apr 10th, 2006, 2:22 PM   #3
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
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.
drifter is offline   Reply With Quote
Old Apr 10th, 2006, 2:24 PM   #4
mongeau
Newbie
 
mongeau's Avatar
 
Join Date: Apr 2006
Location: Fargo, ND
Posts: 29
Rep Power: 0 mongeau is on a distinguished road
Send a message via MSN to mongeau
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.
mongeau is offline   Reply With Quote
Old Apr 10th, 2006, 2:27 PM   #5
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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).
Booooze is offline   Reply With Quote
Old Apr 10th, 2006, 2:29 PM   #6
mongeau
Newbie
 
mongeau's Avatar
 
Join Date: Apr 2006
Location: Fargo, ND
Posts: 29
Rep Power: 0 mongeau is on a distinguished road
Send a message via MSN to mongeau
Quote:
Originally Posted by Booooze
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.

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.
mongeau is offline   Reply With Quote
Old Apr 10th, 2006, 2:40 PM   #7
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
Quote:
Originally Posted by mongeau
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");
	}
?>

That works, thanks alot!
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former.
drifter is offline   Reply With Quote
Old Apr 10th, 2006, 2:48 PM   #8
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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.
Booooze is offline   Reply With Quote
Old Apr 10th, 2006, 5:32 PM   #9
ASHORY
Programmer
 
ASHORY's Avatar
 
Join Date: Dec 2004
Location: Egypt
Posts: 30
Rep Power: 0 ASHORY is on a distinguished road
Send a message via ICQ to ASHORY Send a message via MSN to ASHORY Send a message via Yahoo to ASHORY
so why did you use
include(home . ".php");
like that not like that
include("home.php");
__________________
"^Ahmed.SHOukRY^"
http://www.ashory.741.com
ASHORY is offline   Reply With Quote
Old Apr 10th, 2006, 7:41 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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]
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC