I use global variables on my website such GET,POST,FILES,SESSION
. I wrote my website on a server where register_globals is on
. And i just moved my website to another server where register_globals is off
and i actually do not know how to deal with it.
For exmaple, i have this code:
$do = $_GET['do'];
or
$name = $_POST['name'];
How i understood, i can not do this, php can't extract this data. How can i change my code to receive data from GET,POST,SESSION,FILES?
Thank you
You misunderstand. $_GET
& co are superglobals which are always available and cannot be disabled, your code will always work.
register_globals makes those $_GET
values directly available as variables. Ie instead of $_GET['do']
you could use $do
.
This is the proper way to access the vars and works with register_globals_gpc = off
:
$do = $_GET['do'];
If register_globals_gpc = on
the $_GET
would automatically be extracted and this would work:
echo $do;
So if you are doing it the way you show then all is well. $_GET
, $_POST
, $_COOKIE
, as well as $_SERVER
and $_SESSION
are already superglobal and available anywhere.
The quick and easy way would be using extract
function.
extract($_POST);
extract($_GET);
extract($_COOKIES);
But this is VERY VERY VERY BAD from security and maintainablity aspect! You should rewrite the code, if possible, to:
$variable = $_POST['variable'];
..
when I googled this issue and open the very first serch result it gave me the solution . Try this, Hope it will work for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.