skip to Main Content

What is the Secure and SEO friendly method for redirecting a user to the previous page he was working in PHP.
I have seen people using GET variables to pass url, and I also know that sessions or $_SERVER['HTTP_REFERER'], can be used. But one of my friend told that $_SERVER['HTTP_REFERER'] is not safe
If it is not safe how can we get the previous page URL



  1. You should pass the previous (relative or absolute) URL via GET (urlencode) to the login page, when you redirect to login.

    The HTTP_REFERRER solution is not really secure.

    Login or Signup to reply.
  2. Your Friend is right . $_SERVER['HTTP_REFERER'] is not guarantied to return previous page accurately. My recommendation is to use session and cookie to store the last page. Upon the login check for stored page URL and forward to your desired page and expire the cookie.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top