drudfe0446838 2018-05-23 00:30 采纳率: 0%
浏览 1069

重定向 referer 的功能哪里出错了?

我使用这个index.php将用户重定向到另一个页面,这是它的引用程序功能。如果用户来自没有列出的推荐人,它应该转到特定的url。

除了用户来自没有列出的任何引用者之外,一切都进行得很好。在这种情况下,站点不做任何事情(在同一域中为空白)。我看不出哪里有错误。

<?php
if (isset($_POST["redirect"])) {
  $hash = $_POST["redirect"];

  if ($hash !== "") {
    $origin = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
    $destination = "";

    if($origin == 'http://www.ads1.net/click/cc1/') {
      $destination = 'http://www.example1.com';
    } else if($origin == 'http://www.ads2.net/click/cc2/') {
      $destination = 'http://www.example2.com';
    } else if($origin == 'http://www.ads3.net/click/cc3/') {
      $destination = 'http://www.example3.com';
    } else if($origin == 'http://www.ads4.net/click/cc4/') {
      $destination = 'http://www.example4.com';
    } else if($origin == 'http://www.ads5.net/click/cc5/') {
      $destination = 'http://www.example5.com';
    } else {
      $destination = 'http://www.anothersite.com';
    }

    if($destination != "") {
      echo "<script>window.location.href = '".$destination."';</script>";
    }
  }
}
?>
  • 写回答

1条回答 默认 最新

  • dqm7854 2018-05-27 08:13
    关注

    Try changing your code to this. If $_POST['redirect'] is not set, it will redirect to http://www.anothersite.com. Otherwise if $_POST['redirect'] is not empty, it will redirect according to $_SERVER['HTTP_REFERER']. The only case in which the user will not be redirected is if $_POST['redirect'] is set but empty (i.e. $_POST['redirect'] === ''); I have left a comment in an else block there, you may decide to redirect from there as well?

    $destination = "";
    if (isset($_POST["redirect"])) {
      $hash = $_POST["redirect"];
    
      if ($hash !== "") {
        $origin = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
    
        if($origin == 'http://www.ads1.net/click/cc1/') {
          $destination = 'http://www.example1.com';
        } else if($origin == 'http://www.ads2.net/click/cc2/') {
          $destination = 'http://www.example2.com';
        } else if($origin == 'http://www.ads3.net/click/cc3/') {
          $destination = 'http://www.example3.com';
        } else if($origin == 'http://www.ads4.net/click/cc4/') {
          $destination = 'http://www.example4.com';
        } else if($origin == 'http://www.ads5.net/click/cc5/') {
          $destination = 'http://www.example5.com';
        } else {
          $destination = 'http://www.anothersite.com';
        }
      }
      else {
        // $_POST['redirect'] is set but empty (=== '')
        // if you want to redirect for this case, add a URL here as well e.g.
        // $destination = 'http://www.anothersite.com'
       }
    }
    else {
      $destination = 'http://www.anothersite.com';
    }
    if($destination != "") {
      echo "<script>window.location.href = '".$destination."';</script>";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示