How do I get values from url and append them to existing values in url (php)
I have a link in my page that look like this: a href=?command=value
but when I 开发者_如何学Goclick the link and the page reloads it first load another include php file. That redirect the user based on the cookie. like this: header('Location: ?lang='.$redirect);
So when the page loads the ?command=value is gone.
I need to append &command=value
in the redirecting include file so the url look like this: ?lang=en_US&command=value
I like the http_build_query function the most:
$variables = $_GET;
$variables['lang'] = $redirect;
header('Location: ' . http_build_query($variables));
Like this you keep the existing variables, add your own and use the new query string for the redirect.
Change the redirect line to this:
header('Location: ?lang='.$redirect.'&command='.$_GET['command']);
You would need to do something like:
header('Location: ?lang=' . $redirect . '&' . $_SERVER['QUERY_STRING']);
The above will keep any get data that is associated in tack. codersarepeople will only do the command.
Good luck!
EDIT:
One potential down side to this would be if the lang is already in the QUERY_STRING, it will also be appended, so be cautious of that, depending on the uses.
精彩评论