PDA

View Full Version : php GET and POST vars


gmorphus
09-23-2002, 01:51 PM
Hi,
I'm running on my computer Apache 1.3.26 and PHP 4.2.1

In the previous version when I submitted I form, and it didn't matter if I used the GET or the POST method, I could access the variables directly. Now I seem to not be able to do that, only through the $_GET and $_POST arrays.

I'll to explain myself better:
Let's say i have a form with an input field from type "text" named "user". After submitting the form I want to be able to access this this field's value through $user and not only to the mentioned arrays.

I hope I'm clear enough.

Thank you in advance,
Guy.

mordred
09-23-2002, 02:29 PM
You can affect this behaviour by editing your php.ini and adjusting

register_globals = Off

to

register_globals = On

But those changes were not without any reason - read in the changelog why the PHP developers changed their mind.

Alternatively, you can use extract($_POST); extract($_GET); or import_request_variables() to import all gpc variables into the global scope of your script.

gmorphus
09-23-2002, 06:37 PM
Thank you for your response, but I did that even before I posted the question and it didn't help.
I will check it again.

I need this to be like that not only for my comfort, I need this because sometimes these vars are passed to my page using "get" and sometimes using "post" method.
I can change it to be always "get" but I would preffer it to be "post".

Spookster
09-23-2002, 07:29 PM
I don't believe that you completely understood Mordred's reply. register_globals does not affect whether or not you can use GET or POST. It affects how you retrieve the GET or POST data.

In older versions of PHP the register_globals was set to on. This meant that all of your POST and GET data was immediately available to PHP by simply declaring a variable using the same name as an element in the form. Or you could retrieve those values the proper way by using $variable = $HTTP_POST["elementname"]; .

The PHP engine developers wish to phase that technique out by now setting the register_globals to off by default. This means that you should properly grab the POST or GET data using this means:

$variable = $_POST["elementname"];

$variable = $_GET["elementname"];

gmorphus
09-23-2002, 10:01 PM
Thank you spokster for your explanation but that is exactly what I understood.
I'm sorry for not being clear enough.

I did make register_globals to on, but still couldn't get it to work.

I don't want to use the method you mentioned in this case. The reason for that is that I don't know in advance how the vars were posted to the page.
Hence, I want PHP to "tell" me that by simply making these variables available directly.

Thanks again,
Guy.

mordred
09-24-2002, 02:25 PM
I suppose you also thought about restarting the server, but anyway: what's wrong with import_request_variables()? It serves exactly the purpose you defined here.

firepages
09-24-2002, 02:44 PM
+ you can use $_REQUEST[variable_name] which does not give a hoot if the var is GET or POST.. but you really should know ;)

gmorphus
09-24-2002, 03:51 PM
Ok! thanks!

that should do the work.

thank you all for the help.

gmorphus
09-29-2002, 12:26 AM
All your answer worked great...
but I have noticed that register globals isn't on.

I have searched my HD for php.ini and found only one.
(yes, it is in the php folder)
I have changed the register_globals to on and still doesn't work.

of course I restarted the server...