0

Let's say a user has bookmarked "http://www.example.com/login#/settings". If that user try to access this page when he is logged out, firstly i want him to redirect to login page and then to the bookmarked page using this method

http://www.example.com/authenticate/login?continue=http://www.example.com/login#/settings

NOTE:

  • I'm using MVC architecture
  • Are there any method rather than HTTP_REFERER?

When user enter http://www.example.com/login#/settings ,i want to read whole url including # anchor in my controller file and then only i can set url to

http://www.example.com/authenticate/login?continue=http://www.example.com/login#/settings

so how do i do it??

user1400191
  • 149
  • 1
  • 3
  • 10
  • @BhuvanRikka login page is displayed by authenticate/login and the login controller only get active after login, and also it's not possible to get the whole url including # anchor – user1400191 Aug 01 '12 at 05:03
  • 1
    If I got this right, you already have the answer in front of you. Simple get the value of 'continue' and after authentication use `header` to redirect – asprin Aug 01 '12 at 05:03
  • @asprin Inorder to set the continue value i have to get the whole url including # anchor... How i get this in php??????? – user1400191 Aug 01 '12 at 05:07
  • Use `$continue = $_GET['continue']` – asprin Aug 01 '12 at 05:09
  • @asprin Don't make me mad pls.... Try to figure out what the question is about. When user enter **_http://www.example.com/login#/settings_ i want to read whole url including # anchor and then set it in to the continue parameter. how could i do this???** – user1400191 Aug 01 '12 at 05:16
  • @user1400191, please be nice. If the question is not clear, you will get asked for clarifications and/or receive bad answers. – tucuxi Aug 01 '12 at 05:18
  • @tucuxi sorry for that. i'm bit nervous – user1400191 Aug 01 '12 at 05:19

2 Answers2

0

Depends on how you want to present it to your user. For a simple redirection, use header to send the HTTP Location Header

header("Location: http://www.google.com/");

If you want to give your user some time to read a short message before redirecting them, then you can use header to send HTTP Refresh Header

header( "Refresh: 5; url=newpage.php" ); 

Edit: In order to capture the anchor, you will need to use JavaScript. That information is not available to PHP. In that case, if you use JavaScript to capture the anchor, you might as well write your redirection in JavaScript.

Edit 2: Perhaps the other option is, when you are passing the continue to your program, also send the anchor as another GET variable. So your URI might look like this:

http://www.example.com/authenticate/login?continue=http://www.example.com/login&anchor=settings#/settings

Then use $_GET['anchor'] and concatenate it to the value of $_GET['continue'] with a #.

$uri = $_GET['continue'] . "#" . $_GET['anchor'];
Hameed
  • 2,227
  • 1
  • 21
  • 31
0

You cannot read the part after the # from within PHP. You need to use JavaScript for that. For example, you can use

window.location.hash

To locate the hash-part, if any (it will be '' if no hash, or '#something' if there is one). You can then send this to the controller as a hidden field inside the request.

Community
  • 1
  • 1
tucuxi
  • 17,561
  • 2
  • 43
  • 74
  • I'm using MVC . so where do i put the JavaScript in my platform – user1400191 Aug 01 '12 at 05:27
  • MVC can be applied to anything; I use it in Java and JavaScript and other places. It is only a (good) way of decomposing programs. Please edit your question to explain how your platform works. Most are MVC, but that is not that useful. – tucuxi Aug 01 '12 at 05:32
  • @user1400191 saying it is mvc pretty much ambiguous – ianace Aug 01 '12 at 06:07