dongnunai3125 2010-07-19 12:06
浏览 24
已采纳

登录时记住目的地

When I want to redirect a user to a specific page behind a login wall and they're not already logged in, they get redirected to the homepage where they can login. When they login, they are redirected to a default address.

How do I go about remembering where the users original destination, before they were redirected to the login page?

EDITED WITH SOLUTION

Thanks for the responses. What I've done is set a GET request when the user is detected to not have logged in, using the URL: domain.com/?url=$_SERVER["REQUEST_URI"]

So when the user is redirected to the login page, the address that the user tried to get to is set in the GET value. When the user logs in and authenticates, I do a test to see if there's a GET value, if there is, then append it to the end of the URL address bar.

END EDIT

  • 写回答

3条回答 默认 最新

  • dongren9739 2010-07-19 12:09
    关注

    The easiest way is to add the URL of the current page to the login page as an argument:

    ... not logged in ....
     header("Location: loginpage.php?url=".
             urlencode($_SERVER["REQUEST_URI"]));
    

    (Note, for this, both scripts need to be on the same domain. If they are on different domains, you'd need to use something like "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"])

    and after login, redirecting to that page:

     header("Location: ".$_GET["url"]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度