-3

I entered www.abc.com/123 in the browser THe site detects user is not login so it automatically redirects it to login url www.abc.com/login.

On the login page, I have a script running (Jquery)

I want to get the url of the referral from the login page. Meaning I want to get the url of www.abc.com/123.

How I can achieve this from a jquery code?

ARGO
  • 5,111
  • 4
  • 16
  • 11
  • possible duplicate of [How to get previous page url using jquery](http://stackoverflow.com/questions/2415633/how-to-get-previous-page-url-using-jquery) – Brandon Anzaldi Feb 25 '15 at 02:14
  • I checked and that does not solve it, I was not able to get the first url entered before redirecting the page to login page – ARGO Feb 25 '15 at 02:20
  • var x = document.referrer; alert(x) I have tried this but there is no result, I run it from www.abc.com/login after it was redirected automatically from www.abc.com/123 – ARGO Feb 25 '15 at 02:27
  • How do you detect that a user is not logged in? I am thinking that's the point you need to capture the URL and either send it as a URL parameter or store it in local storage or as a cookie. – PeterKA Feb 25 '15 at 02:44

1 Answers1

1

I think the easiest way to find the last page a user was at is to send it through a $_GET

something like this...

$last_page = '?last=' . $_SERVER['HTTP_HOST'];
$last_redirect = 'Location: http://www.example.com/' . $last_page;
header($last_redirect);

and then on the login page

$login_last_redirect = $_GET['last'];
header($login_last_redirect);

I believe that's how facebook does it

Isaac Dozier
  • 86
  • 1
  • 3
  • Is there a Jquery version of this? I can only run jquery from login page – ARGO Feb 25 '15 at 02:32
  • i'm not sure. I don't mess with jquery too much. Does the redirect process take place within the jquery process? Why can't you define the variable before running jquery script? Unless i'm missing something obvious. – Isaac Dozier Feb 25 '15 at 02:42