在 php 中附加后退按钮的链接

发布于 2024-09-02 01:47:34 字数 154 浏览 4 评论 0原文

有什么方法可以将浏览器的后退按钮附加到任何特定链接吗?

实际上我正在用 PHP 设计一个登录页面。登录后,我希望浏览器的后退按钮打开我想要的任何特定页面,如何在 PHP 中做到这一点?

实际上我不是 PHP 专家,所以我的问题对某些人来说可能听起来很愚蠢。 :P

Is there any way by which I can attach the back button of my browser to any particular link?

Actually I am designing a login page in PHP. After login I want the back button of my browser to open any particular page that I want, how can I do that in PHP?

Actually I am not a PHP guy, so my question might sound silly to some. :P

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫﹏色ふ单纯 2024-09-09 01:47:34

我怀疑您想在用户登录后将其重定向到特定页面,您只需使用 header 函数即可:

header("LOCATION: user-panel.php");

这会将主页重定向到 user-panel.php 页面。

浏览器的后退按钮会返回,直到找到历史记录,只是补充一点,您可以使用 javascript,尽管您的情况可能不需要这样做:

<a href="#" onclick="history.back(); return false;">Go Back</a>

更多信息请点击此处

根据评论更新:

基本上,您在用户首次进行身份验证时设置会话,这是一个例子:

session_start();

// check if the user is already logged in: if yes redirect him even if the back button is clicked

if (isset($_SESSION['logged']))
{
    header("LOCATION: user-panel.php");
}

// below is your own normal code

// your db query if the user specified criteria was met

if (user found)
{
  $_SESSION['logged'] = true; // you should add this line if not already there
  // redirect the user
}

I suspect you want to redirect the user to a particular page after he logs in, you can simply use the header function for that:

header("LOCATION: user-panel.php");

That will redirect home to user-panel.php page.

The browser's back button goes back until there is history found, just to add that you can use javascript for that although this might not be required in your case:

<a href="#" onclick="history.back(); return false;">Go Back</a>

More info here

Update Based On Comment:

Basically you set a session when the user is authenticated for the first time, here is an example:

session_start();

// check if the user is already logged in: if yes redirect him even if the back button is clicked

if (isset($_SESSION['logged']))
{
    header("LOCATION: user-panel.php");
}

// below is your own normal code

// your db query if the user specified criteria was met

if (user found)
{
  $_SESSION['logged'] = true; // you should add this line if not already there
  // redirect the user
}
冷情 2024-09-09 01:47:34

正如 @Sarfraz 正确所说的那样 header 是正确的选择。后退按钮位于浏览器上。 PHP 在服务器上运行,它确实知道客户端浏览器中发生的情况。该页面也可能是从 shell 访问的,例如,您没有后退按钮。

此外,这也不是一个好的页面设计,因为人们希望页面在登录后自动重定向,而不必按后退按钮。

As @Sarfraz correctly says header is the way to go. The back button is on the browser. PHP runs on the server, it does know anything about what happens in the client's browser. The page may as well have been accessed from a shell, for instance, where you have no back button.

Also, that would not be good page design, as people expect the page to rediret automagically after a login, not to have to push the back button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文