返回链接,但不使用历史记录

back link but not use history

本文关键字:历史 记录 链接 返回      更新时间:2023-09-26

如何返回href而不使用历史返回

我试着写这个config.php

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/webapp/';

和index.php(我不知道要取代:

 else{ die("wrong password <a href='"javascript:history.back()'">back</a>");

最终目标是在index.php上是表单登录如果可以的话,下一页。如果错误,那么我想创建返回的链接http://localhost/webapp不http://localhost/webapp/index.php或其他历史url

这就是您想要的:

die("wrong password <a href='"" 
    . substr( $_SERVER['HTTP_REFERER'], 0, strrpos( $_SERVER['HTTP_REFERER'], '/' ) ) 
    . "'">back</a>");

编辑:这将把你送回http://localhost/webapp不http://localhost/webapp/index.php

die("wrong password <a href='"" . $_SERVER['HTTP_REFERER'] . ".'/webapp/'">back</a>");

有一些选项可供选择,每个选项都有缺点

基本URL

您可以使用config.php 中定义的基本URL

die('wrong password <a href="'.$config['base_url'].'">back</a>'); // repalce `"` with `'` to remove `'`; this a preference

这似乎是最好的选择,然而,浏览器再次请求$config['base_url']。与back选项不同,它将后退一步(并将所有字段(输入)保留为提交前的状态)

历史API

 else{ die('wrong password <a href="javascript:history.go(-1)">back</a>');

这可能起作用,也可能不起作用,这取决于某些条件,例如,历史记录中有一组以前的页面。