Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables not passing

Status
Not open for further replies.

MattMend

IS-IT--Management
Dec 24, 2002
3
US
Hi. I am very new to PHP. I have both apache and mysql as well as php installed on my laptop. I thought PHP was functioning correctly because when I do a phpinfo() I get the appropriate diagnostic page.

However in a couple of exercises designed to display variables populated from a form in one case, and in the other, a very simple page to just display the contents of a few of the built-in HTTP variables such as HTTP_REFERER, the variables aren't passing. The pages where the variable contents should display are empty. I've had a friend try the pages on their server and they work fine so I know it's not my code which leads me to server configuration. Any ideas? I"m really stumped.
 
Put the code up anyway just in case it's something weird and finicky?
 
Ok. Here's the more simple of the two since it only involves a single page:

<?php

// File p-4-2.php

echo &quot;<pre>&quot;;
echo &quot;<br><b>Browser :</b> $HTTP_USER_AGENT&quot;;
echo &quot;<br><b>Host :</b> $HTTP_HOST&quot;;
echo &quot;<br><b>Referer :</b> $HTTP_REFERER&quot;;
echo &quot;<br><b>Remote Host :</b> $REMOTE_HOST&quot;;
echo &quot;<br><b>Remote Address :</b> $REMOTE_ADDR&quot;;
echo &quot;<br><b>Remote Port :</b> $REMOTE_PORT&quot;;
echo &quot;</pre>&quot;;

?>
 
Ok, so I get a bunch of undefined variables when I run that... but you'd probably be happy with as much at this point instead of a blank page.

And you said phpinfo() works just fine right?

When you view the source for that blank page is the source also blank, or do you see the php code?

Just for fun, you could also try something like this...

Code:
<?
echo &quot;PHP is interpretting the page!<BR>&quot;;
?>
And this line can say whatever it pleases

Then you've nothing to worry and you'll at least know for sure if php is interpretting your pages.

-Rob


 
Check the phpinfo() output and check the settings for register_globals. I suspect in your case it is off.

If it is off you can use the following to display the value.
$_SERVER['HTTP_USER_AGENT']

Dan
 
Yes register_globals was off. I created a php.ini file (Mac OS X doesn't use one by default) and added a line to enable register_globals. All works fine now.

Thanks to all for the assistance.

Matt
 
MattMend:

This page: recommends that you run PHP with register_globals set to &quot;off&quot;. The manual recommends that you use the superglobal arrays:
All of the values you're trying to use are available through the superglobal array variable $_SERVER.

I recommend using the superglobals because it can improve the maintainability of your code, particularly when you do things with form input values or sessions. When you go back to your code 6 months later, you may not remember where the value in $foo came from. But you it's easy to figure out how the value in $_POST['foo'] got there. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top