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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passed variables ignored? 2

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
After discovering that some form code I had written worked on my local testbed but not on the hosting server, I gradually simplified my code trying to find my problem. But even when I got down to one line of code, it still has the same behavior: it works on my local testbed and one hoster, but not on another hoster (neither of two different domains hosted there). The error is that variables passed in, either by GET or POST methods, are never seen in the PHP code. I have had a more complex PHP application (including many forms submitted and processed) on one of the domains on that hoster for months, and it works fine, but somehow this simple thing doesn't, and I can't for the life of me see what in the more complex code would make it work, or what the hoster could have screwed up in their configuration to make complex code work and simple code not work.

Try and - you will see that the latter works and the former doesn't. The entire content of both formtestprocess.php files is the following:
Code:
<?php
echo "Name: $name<br>\n";
?>
I don't think I can dumb it down any more than that. I have also put a file called "phpinfo.php" on both sites (containing, you guessed it, a call to phpinfo() ), so you can see all the settings and compare. Can someone spot the problem, either what I lack in my code or what the hoster lacks in their configuration? Thanks.
 
You are relying on register_globals set to ON. This setting was changed to OFF since PHP version 4.1.0 (for security reasons).
You should consider writing your code to not rely on that setting - it will be safer and clearer than assuming POST/GET/SESSION are set to local variables.

Whoever runs the proverbs2525 server must have overridden the default setting. Read the chapter on register_global issues in the PHP manual to learn why it is better to have it set to OFF.


This is a common issue/question. Please note that no professional programmer would write code requiring register_globals to be ON.
All right?
?????
 
Yup, you were both right - changing $name to $_GET['name'] solved it (in my real code it'll be POST, but I assume that will work too - it's late here so I'll do that mod in the morning). I had no idea about this issue, and even my favorite PHP reference book teaches direct variable reference (i.e. $var) for form processing. Of course the book predates PHP 4.1 - I don't know how I would do it if I had to deal with an older version of PHP with register_globals off, but fortunately I don't have that situation.

It still remains a mystery why my big DB-handling application works - I only use $var nomenclature there also (it's littered with passed variables, even mixed GET and POST sometimes, so it will be a huge job to fix it all), but it runs fine even on the hoster that apparently has register_globals off.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top