Re: More of an HTML question I think..
| From: | Steve Edberg | Date: | Mon, 31 Jul 2000 00:11:06 +0000 |
| Subject: | Re: More of an HTML question I think.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9081@lists.php.net to get a copy of this message | ||
At 6:26 PM -0500 7/30/00, David VanHorn wrote:
How can I capture the URL result of a filled out form? I know that the form causes the browser to add data to the URL of the target page, but I don't know how to grab that.Form data is appended to the URL only using the GET method. There are a couple of ways to retrieve that info. (1) Environment variables $SERVER_URL, $SCRIPT_NAME, and $QUERY_STRING. $QUERY_STRING contains the variables (everything after the '?' in the URL and before the '#'). You could reconstruct the entire URL via $Url = $SERVER_URL.$SCRIPT_NAME.'?'.$QUERY_STRING; (2) Instead of using $QUERY_STRING, you could reconstruct the data by walking the $HTTP_GET_VARS array: unset($TempArray); reset($HTTP_GET_VARS); while (list($Name,$Val) = each($HTTP_GET_VARS)) { $TempArray[$Name] = urlencode($Val); } $MyQueryString = implode('&', $TempArray); $Url = $SERVER_URL.$SCRIPT_NAME.'?'.$MyQueryString; If some GET variables are arrays (eg; <SELECT NAME="things[]" MULTIPLE> ... </SELECT> ) this gets to be a little more complex, but not much. Some notes: * If you are using the environment vars in a function, you need to GLOBALize them: function make_url() { global $SERVER_URL, $SCRIPT_NAME, $QUERY_STRING; ... } (You could also pass them as function arguments). * You might think of trying environment variable $HTTP_REFERER, but that probably won't be set if scripts are auto-submitting this info. * GET method is limited to (I think) 8 Kbytes by HTTP spec, but some browsers have lower limits. To be safe, if you're approaching 1 Kbyte or more in the URL, you might want to use POST method. That makes the submit scripts a little more complex, but not much. For a PHP example, go to www.phpbuilder.com and search the code libraries for Rasmus' PostToHost function. - steve
I this so that other users can use scripts to submit to my forms. -- www.SpamWhack.com A pre-emptive strike against spam Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9 My transistor sings with unintended parasitic the smoke escapes By Jeff Stout+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+-------------------------------------- FBI Special Agent Dale Cooper ---+