PHP Get urls params for bookmarked pages

Started by mario, March 31, 2009, 08:09:45 PM

Previous topic - Next topic

mario

Often users make bookmarks on page with GET params which are only availibe when you are logged in. Senario: Call bookmark, but you are redirected to the login and than to the start page but not to the bookmark. So we take the url params and save them and after login go back to the requested page.


/**
* @return string $self Komplette URL mit allen Parametern
*/
function get_this_uri_and_params(){
$self = $_SERVER['PHP_SELF'];
$n = 0;
foreach($_GET as $name=>$val){
if(!$n){
$self .= "?";
}
else
{
$self .= "&";
//& ??
}
$self .= $name."=".$val;
$n++;
}
return $self;
}

$self = $this->get_this_uri_and_params();
echo <<<END
<form action="$self" method="post" name="login">
<table>
<tr><td>Loginname:</td><td><input type="text" name="suser" /></td></tr>
<tr><td>Passwort:</td><td><input type="password" name="spass" /></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td><input type="submit" value="Login" /></td><td>&nbsp;</td></tr>
</table>
</form>
END;


Hope this short snippet helps someone