View Full Version : Q: I cant access the global POST data
big_winston
05-13-2003, 07:41 PM
Hi,
Hope someone can help...
I can NOT access the global POST data at the moment.
I have created a text box called "my_box", put it inside the <form> tags in a page called index.php and set the form to call itself when a submit button is pressed. I then try and echo $my_box at the top of the page expecting to see what is entered into the box but nothing ever appears.
Am I missing something obvious? I dont get any errors or warnings and I have checked the PHP.ini file and this is def. set to on:
; Whether or not to register the EGPCS variables as global variables. You may
; want to turn this off if you don't want to clutter your scripts' global scope
; with user data. This makes most sense when coupled with track_vars - in which
; case you can access all of the GPC variables through the $HTTP_*_VARS[],
; variables.
;
; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = On
I know if needs be I can code it to extract the variables manually but I'd rather have them auto register as globals.
Any help much appreciated...
BW
Did you try this?
$my_box = $_POST["my_box"];
echo my_box;
big_winston
05-14-2003, 10:37 AM
no, I have used this before but as I understand (and I am fully aware I may be missing the target by quite some way) but I didnt think that was necessary and I should just be able to reference the POST data by just $my_box??
Weirdan
05-14-2003, 10:50 AM
Posting the html code of your form (and, probably, php code) will be of great help. It's pretty hard to guess what's up with your code while we don't see the code itself :)
big_winston
05-14-2003, 02:17 PM
Ok, I am at work at the moment and the code is at home, but this is the jist of it....
#### File : Index.php ########################
<HTML>
<BODY>
<FORM name="my_form" method="post" action="index.php">
<?php
echo $my_box;
?>
<SELECT name="$my_box">
<OPTION value="0">Option A</OPTION>
<OPTION value="1">Option B</OPTION>
<OPTION value="2">Option C</OPTION>
</SELECT>
</FORM>
</BODY>
</HTML>
#### End Of File ###########################
Weirdan
05-14-2003, 02:50 PM
I've modified this line
<SELECT name="$my_box">
to
<SELECT name="my_box">
and it's work pretty well.
big_winston
05-14-2003, 03:00 PM
sorry - scrub the $ in the select line - that is what I meant! :o
It doesnt work for me it always echos as blank when the page refreshes!
Weirdan
05-14-2003, 03:42 PM
Originally posted by big_winston
It doesnt work for me it always echos as blank when the page refreshes!
Blank? No warnings about undefined variables?
big_winston
05-14-2003, 04:38 PM
NOT A SAUSAGE.
I was fully expecting some warnings as in my previous experience it has given errors if you include that extra line and have register_globals = On. It hasnt and it doesnt give errors without that line as I assume it thinks I am just declaring it as a new variable.
BTW, I am using PHPDEV from firepages.au if thats any help!?
whackaxe
05-14-2003, 05:26 PM
maybe the warnings are turned off? if PHPDEV uses the php-recomended.ini, then itll will have warnings turned off. after developing around 200 lines of code i tested a page with a blatant error and it returned nothing, so i checked php.ini and turned the error warnings on. i nearly cried when i saw all the errors iwas getting :(
Dunno. I use PHPDEV too, and I think the error warning are on by default since I get them all the time.
Weirdan
05-14-2003, 06:24 PM
try var_dump($_POST). May be your browser sends wrong request... I'm confused :confused:
big_winston
05-14-2003, 06:38 PM
The plot thickens...
I installed the PHPDEV version on a friends PC - exactly the same version and it works fine on there!
Bizzarre!
If I ever figure this out I will post the solution here.... The quest continues!
big_winston
05-15-2003, 10:19 AM
Hi,
I gave up with this in the end. How it could work on one PC and not another using exactly the same install of PHPDEV on both is beyond me.
Now I use :
$my_box = $_POST["my_box"];
echo $my_box;
and this works, shame its not how I wanted but I can put up with the extra line of code per box!! :rolleyes:
Thanks for your help with this guys.
bcarl314
06-12-2003, 07:19 PM
Try this:
Make a page as so:
phpinfo.php
----------------
<?php
print phpinfo();
?>
Find out if regiser_globals is really on!
I ahd a session_savepath issue once that I swore I changed and was still getting session problems, so I checked phpinfo() and low and behold, it wasn't set right. It was in the php.ini file, but I was running on a WinXP box and ploped a copy of it in my %SYSTEM_ROOT% directory and voila, it worked.
Nightfire
06-12-2003, 09:16 PM
You don't need to use print or echo with the phpinfo function
But that shouldn't make a difference anyway....if the register_globals is on in the php.ini, then it will be in the phpinfo() since the phpinfo() gets its info from the php.ini
firepages
06-13-2003, 02:13 AM
ignoring your register_globals setting & assuming you are using php>=4.1.* you should be using $_POST,$_GET,$_SERVER etc regardless !
$HTTP_POST_VARS etc should also be avoided as they are depracated
There are workarounds , <?extract($_POST);?> etc but they are essentially hacks.
Why ? well cos eventually most hosts will switch to register_globals=off and your code will not work.
If you use $_POST etc then it will work regardless of thier configuration.
I dont want to go into whether the whole register_globals = on/off debacle is right or wrong, because, at the end of the day the descision has already been made for us.
big_winston
06-13-2003, 12:44 PM
Ok, thanks for clearing that up for us. I assumed it would be good coding practice to use the $_POST / $_GET, guess I was just being lazy! :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.