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!

variables not passing between pages?

Status
Not open for further replies.

TTEL

IS-IT--Management
Jun 20, 2004
68
GB
I am modifying some scripts I have already written to port to a new site on a new machine.

However when passing variables appended to the URL between one page and another the variables are not recognised by the receiving page. (error is 'undefined variable')

This works fine on the old site but errors on the new installation.
Is this some sort of environmental setting in php.ini.

I think old site is PHP 4 and new site is PHP 5.

Any ideas what's wrong?


thanks,


Andy.
 
Looks like the old site had [tt]register globals[/tt] set to on, while the new one has it off. Off was introduced in PHP for security reasons. Rather than just calling a variable with [tt]$variable[/tt] (which assumes register globals on), you should code in order to make your page as portable as possible -- work with register globals on or off. This means you need to reference variables coming from URL via [tt]$_GET['variable'][/tt]. This way your code will be more secure, more portable and easier to understand.
 
I guess your problem is the register_global setting in the php.ini file. Now, for security, register_global is off. You should reference the posted variables with $_GET or $_POST.

Read: Variables from outside PHP
 
Check out the settings with phpinfo(). It will tell you exactly what options are set differently.
Read up on it in the manual.
It is highly advisable to write all scripts you write in a fashion that they will not depend on register_global ON or on any specific error setting level.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top