 |
 |
PHP: Can't pass variables from FORM using POST....Related to Panther upgrade?
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
I'm having a pretty weird problem here and I am pretty sure its due to my upgrade to Panther. While I'm loving Panther this one problem is definitely giving me a big headache.
I was trying to pass some variables to MySQL using a form, pretty basic stuff. The pages were working before Panther (I'm almost positive but I did make some changes before the upgrade) but now it doesn't seem to work. When I did upgrade to Panther, I had to turn on PHP again and I'm wondering if maybe this is a newer version and I missed something else to make the passing of variables using POST possible?
I did create a couple basic pages for testing to see if I was losing my mind or what. Here is the form page:
[php]
<html>
<head>
<title>Basic Form</title>
</head>
<body>
<form action="parse.php" method="POST">
<input type="text" name="user">
<br>
<textarea name="address" rows="5" cols="40">
</textarea> <br>
<br>
<input type="submit" value="hit it!">
</form>
</body>
</html>
[/php]
And here is the "parse" page, that should just show the variables:
[php]
<html>
<head>
<title>Parser</title>
</head>
<body>
<?php
print "Welcome <b>$user</b><p>\n\n";
print "Your address is:<p>\n\n<b>$address</b><p>\n\n"; ?>
</body>
</html>
[/php]
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2003
Status:
Offline
|
|
to use the variables like $user and $address, I think you have to enable register globals, either in php.ini or by allowing overrides from .htaccess in httpd.conf and adding the line `php_value register_globals "On"` to a .htaccess file where this script resides...
Short of that, just use the variables as they are meant to be used:
$_POST['user'] and $_POST['address'] (or use $HTTP_POST_VARS in place of $_POST if the short form will not work for some reason).
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
...or if you're in a hurry, add:
extract($_POST);
which will let you use your original code, as this gives you the same result as Register Globals.
It's nothing to do with Panther - it's PHP upgrading its security so that variables have to be explicitly set. It also forces you to write more considered code!
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
I usually just grab the variables from the POST like this:
$newVarName=$_POST['passedVarName'];
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: May 2000
Location: ON, Canada
Status:
Offline
|
|
With your help I'm now able to pass variables from a form submission, but I can't just fill out the variables on my own from the url
If a form field contains name=darcy and action='script.php' method=post
and script.php has the code $name=$_POST['name']; and I can reference it that way no problem
why can't I do in the url bar of my browser:
http://www.domain.org/script.php?name=darcy
I did a search on my hd and I can't find php.ini . I used "sudo find / -name "php.ini" "
|
|
Macbook (white glossy) 2.16GHz | 4GB RAM | 7200RPM HD | 10.5.x
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
for that, you need to use method=GET in your form. Get uses the ?var=stuff method, and Post is not shown in the browser address bar.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: May 2000
Location: ON, Canada
Status:
Offline
|
|
Actually, for address bar applications you have to use $_REQUEST. At least that's what I learned in another MacNN post and fixed my problems.
I now use this: extract($_REQUEST);
|
|
Macbook (white glossy) 2.16GHz | 4GB RAM | 7200RPM HD | 10.5.x
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
Hmm, I've seen that, too. I wonder what the difference is between GET and REQUEST...
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: May 2000
Location: ON, Canada
Status:
Offline
|
|
GET means get things from the url, while POST means get things from the HTTP header. ( I think)
|
|
Macbook (white glossy) 2.16GHz | 4GB RAM | 7200RPM HD | 10.5.x
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2003
Location: SoCal
Status:
Offline
|
|
Originally posted by darcybaston:
Actually, for address bar applications you have to use $_REQUEST. At least that's what I learned in another MacNN post and fixed my problems. 
I now use this: extract($_REQUEST);
just FYI,
$_REQUEST gets all variables from GET, POST, and COOKIE so it's probably the best one to use (at least the simplest).
Also,
If you want to go back to just making your original script work turn register_globals back to "on", but it is a security risk as people can override your variables using a well-formed url like yourpage.php?logon=true, and if your php page is looking for $logon then they are in. Also, a reason not to use extract($_REQUEST).
If you're interested, I found the area on php.net that describes this:
http://us4.php.net/manual/en/securit...terglobals.php
(Last edited by si_lance; Dec 21, 2003 at 05:53 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by si_lance:
just FYI,
$_REQUEST gets all variables from GET, POST, and COOKIE so it's probably the best one to use (at least the simplest).
Also,
If you want to go back to just making your original script work turn register_globals back to "on", but it is a security risk as people can override your variables using a well-formed url like yourpage.php?logon=true, and if your php page is looking for $logon then they are in. Also, a reason not to use extract($_REQUEST).
Not strictly true, unless the order of Request variables is changes - GET is used first (by default), then POST, so POST variables will override in most cases.
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2002
Location: Chicago, IL
Status:
Offline
|
|
The confusion is due to the fact that you didn't have to do anything to use POST/GET variables before- they were made available automatically. This was seen as a potential security flaw (which it could be), so this feature (called resigter_globals) was disabled in version 4.2.
You can override the setting, but it's just as easy to follow the advice of madmacgames.
Most of the PHP tutorials online haven't been updated to reflect this change, though, so I'm guessing a lot of people (including myself at one point) get really confused as to why they can't use their variables.
(eidt: whoops, somebody already said this. oh well.)
|
We need less Democrats and Republicans, and more people that think for themselves.
infinite expanse
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|