Hello everyone!

is there any simple way of knowing which page within the site the user came from? Since after the user do something such as logging in and i want to be able to redirect the user back to the page from which he/she came from..

Thanks alot!

    furtivefelon wrote:

    Hello everyone!

    is there any simple way of knowing which page within the site the user came from? Since after the user do something such as logging in and i want to be able to redirect the user back to the page from which he/she came from..

    Thanks alot!

    You could store the link in the URL.

    ie <a href="http://www.pathtologin.com/login.php?previous=article/01/page2"> login </a>

    then send them back to $_GET['previous'];

    I've seen that a few times on websites.

      you can also look at $_SERVER['HTTP_REFERRER']
      from the manual:
      'HTTP_REFERER'
      The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

      Hope that helps.

        Thanks alot! The second one works fine, i encased redirect in the following function:

        function redirect($page){
        	if($_SERVER['HTTP_REFERER'] != ''){
        		header('Location: '.$_SERVER['HTTP_REFERER']);
        	}
        	else{
        		header ("Location: $page");
        	}
        }
        

        So that i can pass a default page if HTTP_REFERER doesn't work..

        Thanks again!

          Write a Reply...