 |
 |
HTTP & Forms : where are name-value pairs stored?
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Hey guys,
Need to know. When an web FORM is submitted, where are the name-value pairs stored? Apache? Client? or Server?
Are they stored in an array in any of those locations? What is the method or call to that array?
I would like to be able to parse the name-value pairs 'dynamically'.
I read the HTTP specs, but I couldn't find anything. Gonna check out Apache next.
Thanks! Hope you guys know.
|
|
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
They're submitted as part of the HTTP request, and therefore it's either Apache or the CGI (or other web-based scripting environment) that parses them. It doesn't really matter which. The parsed name-value pairs are then stored in memory on the server while your script executes.
POST data needs to be parsed. I think PHP does this automatically, and there are several PERL libraries around for doing it...
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
One of the original (and still one of the best) resources on understanding the fundamentals of CGI can be found at
http://hoohoo.ncsa.uiuc.edu/cgi/
The most direct answer to your question is that form parameters are never stored - they are passed like a hot potato from the client (the browser) to the server (Apache) to the handler (CGI perl script, PHP, servlet, whatever.) If the handler chooses to store the data (perhaps to a database), so be it.
Form variables are passed from the server to the CGI differently depending on the method the form was submitted. If the form is being submitted as a GET, the data gets to the handler in the form of an environmental variable, QUERY_STRING. If the form is being submitted as a POST, the data is piped to STDIN on the handler.
Parsing either is straightforward, but there's no need to do it yourself. If you're writing a perl CGI, use CGI.pm which will do it all for you automatically; if you're writing a Java servlet, just look in the HttpServletRequest object; other environments have similar objects or methods.
Erik
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
|
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
Your post doesn't say what language you're writing in. Where the values technically exist is irrelevant, unless you're rewriting Apache or something. All you need to know is how to get at them in your language. - In PHP, they're all pushed into variables at the start of the script. So, a field called 'name' would become a variable called $name.
- In Perl, they're stored in various parts of the $ENV array. Go read a Perl reference to find out how to get them.
- In Java Servlets, they're part of the Request object. Again, go read a reference.
- I haven't used JSP, ASP or WebObjects.
So which language are you using?
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
I'm using PHP.
Does PHP have anything similar to the $ENV array of Perl? It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
|
|
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by NeoMac:
I'm using PHP.
Does PHP have anything similar to the $ENV array of Perl? It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
The $ENV hash of PERL does not store the data submitted from a form in name-value keys. It stores environment variables in name-value pairs.
You can create arrays from things in an HTML form, see the PHP FAQ at http://www.php.net/FAQ.php#8.1
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
Originally posted by NeoMac:
It would be much easier to write a script and pull the name-value pairs from the array, rather than have to hard code the extraction of values into the script for each specific web form I use.
There's no "extraction of values" involved in PHP because the form field names become the variable names.
The only time you need to "extract" key-values is when you're dynamically creating forms and variable names can't be "hard coded". In this case, you can name your fields numerically (e.g. field1, field2, etc), then add a hidden field with the number of fields in it. Extraction code would look like:
for ($i=0;$i<$numFields;$i++){
$fieldName="field".$i;
$keyval_array[$fieldName]=${$fieldName};
}
In the above case, $keyval_array["field1"] will have whatever data was entered in field1. (Or it should, it's untested code.)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Angus_D's response solves the problem.
Writing the form values into an array will suffice for my purposes.
Thanks. 'A+' Angus_D. 
|
|
"Last time the French asked for more evidence, it rolled through France with a German flag." - David Letterman
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|