Hey,
I'm trying to redirect from one page to another while retaining the parameters.
e.g. if I have a page page.php?param1=1¶m2=2, what's the easiest way to extract "param1=1¶m2=2"?
Hey,
I'm trying to redirect from one page to another while retaining the parameters.
e.g. if I have a page page.php?param1=1¶m2=2, what's the easiest way to extract "param1=1¶m2=2"?
i would do
$querystring = '?'
foreach($_GET as $k=>$v) {
$querystring .= $k.'='.$v.'&';
}
$url .= substr($querystring, 0, -1);
where $url already contains everything before the ?
you could also use $_SERVER['QUERY_STRING'] but as per the PHP manual:
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. *There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. *
Use $_SERVER['QUERY_STRING'] to access everything after the question mark.
So if you have the url:
http://www.sample.com/page.php?param1=1&param2=2
then this:
$url = "http://www.sample.com/page2.php?".$_SERVER['QUERY_STRING'];
echo $url;
will return:
http://www.sample.com/page2.php?param1=1&param2=2