[Solved] PHP - Problem with receiving ******?id=4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
uuplunkeruu
Forum Newbie
Posts: 2
Joined: Tue Mar 23, 2004 6:43 pm
Location: Miami

[Solved] PHP - Problem with receiving ******?id=4

Post by uuplunkeruu »

I have two files on my system the first 1 is test.htm and it contains:

<a href="test1.php?id=4">Link</a>

The second file contains (test1.php)

<?php
if( $id == 4) { print "It works"; }
else { print "No work"; }
?>

For some reason it never prints "It works" I always get "No work". I am running on a Debian 2.2.24, Apache 2.0.48, PHP 4.3.4.... I don't know if it is a Apache Problem or a PHP problem. I have tried seeing if it was apache problem by doing request_headers() and headers_sent() and response_headers() they all work fine.

Any help would be greatly appreciated.

Thank You...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

<?php
if(!empty($_GET['id']) && $_GET['id'] == 4) {
    echo 'It works';
} else {
    echo 'No work';
} 
?>
The reason yours didn't work is because register_globals is off (in php.ini) so when you use a url like ?foo=bar then $foo isn't set, only $_GET['foo'] is. See http://php.net/variables.predefined for more info
uuplunkeruu
Forum Newbie
Posts: 2
Joined: Tue Mar 23, 2004 6:43 pm
Location: Miami

Thanks for the help

Post by uuplunkeruu »

Thanks for the help that worked. I have only been working with PHP for about 2 days now and I have to move a site from 1 host to another and different vers etc....


Thank You.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Click the first link in my signature.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

sami, i think that was a valid question for this forum
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

If it hadn't been asked 10.000 times before, sure it would have been. This question gets asked every day, sometimes a couple of times on the very same day.

Read the General Posting Guidelines before you post!!!
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

oh, sorry
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Mark.. do you think it would be better to turn the register_globals on as opposed to using $_GET?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

it isnt

it is turned off by default, for a good reason

it can seriously compromise the security of your applications

also most hosts, have it turned off, so to ensure your scripts work in a 'real-world' environment, you should always code in this way
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Thanks Malcolm.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

no problem :)
Post Reply