登录后如何转发到正确的网址 [英] How to forward to the correct URL after login

查看:29
本文介绍了登录后如何转发到正确的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,其中有一个包含日志列表的网页.现在我通常会为某些用户提供访问该页面的链接例如:http://172.20.22.77/someapp/results.htm?id=45

I have a website which has a web page containing list of logs. Now I usually give the link to access that page for some user eg : http://172.20.22.77/someapp/results.htm?id=45

现在当一些用户点击这个.它会给他一个登录屏幕.但登录后它不会去到意图的页面.我使用会话来实现网站,它有很多页面,因此会话用于跟踪浏览页面的用户.

Now when some user clicks on this .It would give him a login screen .But after login it does not go to the page that was intented . I am using sessions to implement the website and it has many pages, hence session is used to track the user browsing the page.

请告诉我如何重定向用户登录后询问的 URL.

kindly let me know how can i redirect the URL being asked after user logs in .

推荐答案

在重定向到登录页面之前,将用户访问的 URL 放入会话中.然后,登录页面可以在对用户进行身份验证后重定向回存储的 URL.

Put the URL the user was accessing in the session before redirecting to the login page. The login page can then redirect back to that stored URL after authenticating the user.

在需要登录的页面上:

session_start();
$_SESSION['after_login'] = $_SERVER['REQUEST_URI'];
header("Location: login.php");

在登录页面:

session_start();
if (user has entered correct username and password) {
    header("Location: http://example.com" . $_SESSION['after_login']);
}

这篇关于登录后如何转发到正确的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆