views:

50

answers:

3

Hi. I have a link in my page that look like this: a href=?command=value but when I click 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

A: 

Change the redirect line to this:

header('Location: ?lang='.$redirect.'&command='.$_GET['command']);
codersarepeople
A: 

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.

Brad F Jacobs
+6  A: 

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.

Blizz
+1 Nicely written. Especially like how it overwrites the lang variable.
Brad F Jacobs