【问题标题】:back link but not use history反向链接但不使用历史记录
【发布时间】:2016-01-26 14:16:29
【问题描述】:

如何恢复一个 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 或其他历史记录网址

【问题讨论】:

  • 然后将href设置为http://localhost/webapp/
  • 如何使用 include config.php 变量放置它?...所以当我在其他站点上使用此脚本时,我只需编辑 config.php
  • 你能用die("wrong password &lt;a href=\"" . $_SERVER['HTTP_REFERER'] . "\"&gt;back&lt;/a&gt;");这个吗?
  • 优秀....我的意思是...在谷歌搜索我没有找到答案....最后一个问题....在谷歌如果我想我应该使用什么关键字搜索有关此 http_referer 的帮助?
  • 也许您可以使用substr( $_SERVER['HTTP_REFERER'], 0, strrpos( $_SERVER['HTTP_REFERER'], '/' ) ) 删除文件名

标签: javascript php base-url


【解决方案1】:
die("wrong password <a href=\"" . $_SERVER['HTTP_REFERER'] . ".'/webapp/'">back</a>");

【讨论】:

【解决方案2】:

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

基本网址

您可以使用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>');

根据某些条件(例如,历史记录中有一组以前的页面),这可能有效,也可能无效。

【讨论】:

    【解决方案3】:

    这就是你想要的:

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

    编辑: 这会将您发送回http://localhost/webapp 而不是http://localhost/webapp/index.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 2016-08-21
      • 2011-10-28
      • 2013-09-11
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      相关资源
      最近更新 更多