Jump to content

Variable Question PHP4 to PHP5


cytech

Recommended Posts

Hey All,

 

I just picked up a small edit job from this guy who's admin panel didn't work, so I went in and found out that it was developed way back in the day.

 

So all of the variables are set almost like globals.

 

Example:

$pageTitle
$pageDescription

 

Instead of

$_POST['pageTitle'];
$_POST['pageDescription'];

 

Now he is currently running the latest version of php, of course nothing works becuase php5+ doesn't regonize $pageTitle as $_POST['pageTitle'], is there a quick fix to this mess? or do I need to edit each variable to make it work again??

 

Thanks for any advice!

 

 

Link to comment
https://forums.phpfreaks.com/topic/139890-variable-question-php4-to-php5/
Share on other sites

The quick fix, which I highly do not recommend due to security issues is you can turn register_globals on in the php.ini.

 

But yea it is better to define them at the top of the page so you know what is coming in. IE for each variable that is retrieved from post you can just put this code at the top of the page:

 

$pageTitle = isset($_POST['pageTitle'])?$_POST['pageTitle']:null;
$pageDescription = isset($_POST['pageDescription'])?$_POST['pageDescription']:null;

 

And that is much better alternative than turning back on register_globals.

I actually kept globals off.

 

One of my buddies said do extract($_POST) for the areas that need it, that did the trick.

 

I hate working on sites like this, you want to go ahead and overhaul it but its just not in the cards so to speak haha

 

Yea extract works, but still gives the same flaw with any post variables. But it is more secure than having the cookies/session/post/get all being made into their variables.  You could even use a loop in place of extract with an array of defined variables coming from the form, but yea. Another option I guess.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.