【问题标题】:allow only urls that have a parameter in只允许有参数的 url
【发布时间】:2016-11-02 14:00:22
【问题描述】:

所以,我有一个url,它重定向到另一个执行Double Meta Refresh (cleans referer) 的操作,我只想在url comes with a parameter 时允许看到second url

当前设置为:

urlA.php  --DMR--->  urlB.php

我希望用户能够看到urlB only if they come from urlA,但由于中间人已被清除,我认为我无法通过.htacces 中的推荐人进行检查。

所以我在考虑检查一个参数,所以 urlB 只有在特殊参数出现时才能访问,例如:

urlA.php  ----DMR--->  urlB.php   ///NOT POSSIBLE

urlA.php?key=xxxx  ----DMR--->  urlB.php   /// POSSIBLE

提前谢谢你。

【问题讨论】:

    标签: php .htaccess url parameter-passing url-parameters


    【解决方案1】:

    当然,如果你传递一个 GET 参数,你可以使用:

    <?php 
    if(!isset($_GET["key"]) || $_GET["key"] !== "urlA.php"){
       die("you must come from a certain page" );
    }else{
      echo "You came from the right place";
    }
    

    【讨论】:

    • 我收到以下错误:致命错误:无法在 /home/XXX/test 中的表达式结果上使用 isset()(您可以改用“null !== expression”) .php 在第 4 行
    • 这使它起作用,但是如果密钥不是确切的密钥,您能否改写它以便“死”? (这是因为我有很多 html 内容,只有在密钥正确的情况下才想加载。
    • 三重 === 将确保它是正确的键,请提供一个不匹配的示例,您需要将“urlA.php”更改为您传递的任何参数:)
    • 例如,如果您有“key=xxxx”,则需要将代码更改为 if(isset($_GET["key"]) && $_GET["key"] === " xxxx"){
    • 是的,我明白这一点,但我在想类似 if key (different from) XXX then DIE else continue 我知道我表达它很糟糕:P
    猜你喜欢
    • 2014-06-10
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2021-10-23
    相关资源
    最近更新 更多