Page 1 of 1

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

Posted: Tue Mar 23, 2004 6:43 pm
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...

Posted: Tue Mar 23, 2004 6:46 pm
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

Thanks for the help

Posted: Tue Mar 23, 2004 11:39 pm
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.

Posted: Tue Mar 23, 2004 11:44 pm
by m3mn0n
Click the first link in my signature.

Posted: Wed Mar 24, 2004 7:35 am
by magicrobotmonkey
sami, i think that was a valid question for this forum

Posted: Wed Mar 24, 2004 8:19 am
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!!!

Posted: Wed Mar 24, 2004 8:24 am
by magicrobotmonkey
oh, sorry

Posted: Wed Mar 24, 2004 9:39 am
by Steveo31
Mark.. do you think it would be better to turn the register_globals on as opposed to using $_GET?

Posted: Wed Mar 24, 2004 12:42 pm
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

Posted: Wed Mar 24, 2004 2:22 pm
by Steveo31
Thanks Malcolm.

Posted: Wed Mar 24, 2004 2:23 pm
by malcolmboston
no problem :)