【问题标题】:Redirecting an URL just for a given referring URL [duplicate]仅针对给定的引用 URL 重定向 URL [重复]
【发布时间】:2017-12-10 10:11:55
【问题描述】:

我有一个网站(例如https://example.com),并且它(除其他外)有一个名为origpage.php 的页面。但是,当来自给定域(例如http://example.net)的访问者想要打开origpage.php 时,我不想打开它。我希望这个访问者被重定向到另一个页面,例如。 otherpage.php。 我该怎么做? (我认为“问题重复”并非如此。)

【问题讨论】:

  • 您可能正在寻找$_SERVER['HTTP_REFERER']parse_url
  • 你是说当一个人使用https://example.com/origpage.php 时,让他留在页面上。但如果他使用http://example.net/origpage.php,那么将他重定向到http://example.net/otherpage.php
  • 没有。如果有人想打开https://example.com/origpage.php,那么这个页面就会被打开。除非有人来自http://example.net。他必须被重定向到https://example.com/otherpage.php

标签: php url redirect


【解决方案1】:

试试这样的:

if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
    $domain = str_ireplace('www.', '', parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST));

    if ($domain == 'example.net') {
        header('location: otherpage.php');
        die();
    }
}

【讨论】:

    猜你喜欢
    • 2014-04-19
    • 2012-03-19
    • 2015-12-23
    • 2012-11-20
    • 1970-01-01
    • 2017-09-22
    • 2013-02-05
    • 2013-02-24
    • 2012-05-12
    相关资源
    最近更新 更多