开发者

How to direct a user to the referrer page after login?

开发者 https://www.devze.com 2023-04-12 02:30 出处:网络
开发者_如何学CLets say the site has a user account system that uses sessions to login/verify etc.

开发者_如何学CLets say the site has a user account system that uses sessions to login/verify etc.

So let say i send somebody the link domain.com/photos?id=3akK90 and they must be logged in to see it. So naturally the site will ask them the login but after login the home page will show, so how can i do it so that there is a referrer they should be able to login and go directly to that page.


I'm presuming you're redirecting to the login. Capture the URL they initially went to, store it in a session variable and after the login redirect them.


That's a very broad question, perhaps looking into $_SERVER['HTTP_HOST'] will help. When the user initially goes to the URL, the PHP will know the URL they came to. When the login is complete, the PHP can redirect to that URL with a Location header


on /photos

check for user login
if no user login
  save complete url in session
  forward to /login.php

on /login.php

when you catch the post
if the login is successfull
  if that session variable exists and not null
    forward to the complete url that was saved
0

精彩评论

暂无评论...
验证码 换一张
取 消