PHP variables - $ _POST mixed with variables with the same name

On the same page I have

$hello = 'Hello!'; $_POST['hello'] = '123'; 

If I echo $ hello, instead of getting "Hello!" I get "123". How to handle $ _POST variables and variables with the same name?

This is an example of a real problem:

I have a registration form that looks like this (here is an example of fields). Each input field has a label, and the string variable in the label has the same name as the input.

 <form id="form1" action="post.php"> <span class="label"><?=$fullname?></span> //$fullname='Please enter your name'; <input name="fullname" id="fullname" type="text"> <span class="label"><?=$email?></span> //$email='Please enter your email'; <input name="email" id="email" type="text"> <input name="button1" id="button1" type="submit"> </form> 

When I submit the form, I submit it to the same page, and I show the values ​​that the user has filled out. Only now, instead of $ fullname, which displays the value of the $ fullname variable, it displays the value of $ _POST ['fullname']. Why is this happening?

+4
source share
5 answers

The problem is probably related to register_globals in the php.ini file. Turn it off, restart php and it should be fixed.

Try this to verify the setup at the time of code execution:

 echo ini_get("register_globals"); 
+3
source

You probably turned register_globals on, which you have been advising for many years :) for more details see here: http://php.net/manual/en/security.globals.php

+5
source

You must set the method = "POST" attribute in the form declaration. Perhaps you have the register_globals option.

+1
source

Check php.ini for register_globals parameter. Most likely it is turned on, you should turn it off.

+1
source

Well, if register_superglobals is off, you do something like this in your script

as

 foreach($_REQUEST as $key => $val) // or $_POST or $_GET $$key = $val; 
+1
source

All Articles