Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Post variables

Tags:

php

In my old project, post variables used as $var_name instead of $_post["var_name"]. So i need to change code in all files. So do i want to change anything((Auto extracting option)) in php.ini to handle this without changing coding. thanks.

like image 758
Act DEV Avatar asked Aug 02 '26 14:08

Act DEV


1 Answers

Your old project used a now deprecated (since 5.3) and removed (since 5.4) feature called "register globals". Please read on why this feature was removed: http://php.net/manual/en/security.globals.php

In short, no, you do not want to change php.ini so that your old application can work. Instead, you will more likely want to repair your old application to work without register globals.


That said, if this is not a public facing application or security is not an issue, there is a way you can configure php.ini even for PHP 5.4 to have your application work.

WARNING: this involves changing your php.ini file so that the effects of register globals is emulated. This means all PHP scripts will be subjected to the effects of register globals, not just the ones you want.

As mentioned, extract($_REQUEST); will essentially accomplish what register globals used to. Now, using the auto_prepend_file directive, you can run this line of code before every script.

That is, save this file somewhere (preferably in your PHP include path) and, say, call it register_globals.php.

<?php
extract($_POST);

Now in php.ini, add this line (the path may be relative to your PHP include path).

auto_prepend_file = "register_globals.php" ; emulates register_globals

The effect of this change is that require("register_globals.php"); happens before any script runs.

like image 77
erisco Avatar answered Aug 04 '26 03:08

erisco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!