PHP referring URL

06.Sep.2010

Very often we have a situation where we need to change users address back, from where he came. It is mostly used on pages where user should login or register. To get him back we could send previous URL as parameter in login or registration form.

Add this code inside your form to send your referring URL as parameter.

1
2
3
4
5
//get referring URL
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
 
//set referring URL
echo '<input type="hidden" value="' . $url . '" name="referring_url" />';