Re: [php] How to get request url string and server hostname
| From: | Erik Price | Date: | Tue, 25 Jun 2002 19:22:55 +0000 |
| Subject: | Re: [php] How to get request url string and server hostname | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103824@lists.php.net to get a copy of this message | ||
On Tuesday, June 25, 2002, at 02:56 PM, Harriet Xing wrote:
Would anyone know how to get the http request url string in php? i.e., if the request is "http://www.myserver.com/test.php?param1=123", how can I obtain this string in test.php?$request = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']; However, I don't like using $_SERVER['QUERY_STRING'] because if there are empty GET variables, it grabs them. So, if you prefer, you can do this: $getVarsArr = array(); foreach ($_GET as $getVarName => $getVarVal) { $getVars[] = $getVarName . "=" . $getVarVal; } $getVarsStr = implode("&", $getVars); $request = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "?" . $getVarsStr; Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com