LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Can't read from passed headers (https://www.linuxquestions.org/questions/programming-9/php-cant-read-from-passed-headers-161527/)

uuplunkeruu 03-23-2004 05:37 PM

PHP Can't read from passed headers
 
I have code like this

On one page say test.htm I have this:
<a href="test1.php?id=4">Link</a>

On test1.php I have
<? if( $id == 4 )
{ print "This works"; }
else
{ print "This does not work"; }
?>

It will always say "This does not work"
I am running PHP 4.3.4, Apache 2.048, Linux Debian 2.2.24.

Thanks

uuplunkeruu 03-23-2004 05:57 PM

I figured out that the headers are not being sent from page to page by using if(headers_sent()) {pint "blah" } ... If anyone knows if the fix is in apache or in PHP? Or something else....

Thanks

uuplunkeruu 03-23-2004 06:18 PM

OK now I am confused if I run this code:
<?php
if(headers_sent())
{
if($id == 4)
{ print "YES! It is Equal to 4";
}
else { print "Not Working!";
print "<a href=\"test1.php?id=4\">Link</a>";
}
}
else { print "not working"; }



$headers = apache_request_headers();

foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}


I get this output:

not workingAccept: */*
Referer: http://68.213.252.148/test2.htm
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: 68.xxx.xxxx.xxx

uuplunkeruu 03-23-2004 06:22 PM

OK I am completely OFF the Headers are sent.

shortfuse 03-23-2004 11:53 PM

Newer versions of php have 'Register_Globals=Off" by default in your php.ini. Turning that on represents certain security risks so to access $id use "$_GET["id"]'. The following code should work as you expect.

Code:

<? if( $_GET["id"] == 4 )
{ print "This works"; }
else
{ print "This does not work"; }
?>


uuplunkeruu 03-24-2004 04:38 PM

Got it working thanks.


All times are GMT -5. The time now is 09:35 AM.