Tomek Wojtek Tomek Wojtek - 4 months ago 8
PHP Question

redirect doesn't include whole querystring

I'm trying to redirect, but it doesn't include all the parameters in the url

if (!empty($_POST['nazwauzytkownika']) && $_POST['haslo'])
{

removed..


if (isset($_GET['redirect']))
$redirect = $_GET['redirect'];
else
$redirect = 'http://*****.pl/konto/?a=powitanie';


header("Location: $redirect");

}


If
$_GET[redirect]
contains
http://localhost/forum/?p=thread&threadid=9
, it only redirects to
http://localhost/forum/?p=thread

Answer

it is not redirect problem but url problem
every GET parameter should be urlencoded

$redirect = rawurlencode($redirect);
?>
<a href="some.php?redirect=<?=$redirect?>">

then you will have your redirect param inact and can use it for redirect.

though it's considered as bad practice as your script can be used for phishing links.

it's better to pass just url identifier, and then read an url itself from db/session/whatever server side storage