douliaotong4944 2019-04-12 13:10
浏览 64

如何使用PHP在重定向页面中检索原始URL

Let say I have redirect rule on url example.com which redirect to newurl.net. How can I get original url on newurl.net in order to be used and handled with some details or just to be printed on new destination.

Thank anyone for help.

  • 写回答

1条回答 默认 最新

  • dqfkd82886 2019-04-12 13:12
    关注

    If it's not external You can use

    $_SERVER['HTTP_REFERER']
    

    And it will give you the referer which is what you want.

    See Acquiring referral after a PHP redirect for more informations.

    But if you are trying to get to another website, the browser will overwrite the headers so you need to do it some other way.

    You can store it in session.

    //Save it in your first website
    $_SESSION['REFERER'] = $_SERVER['HTTP_REFERER'];
    

    And then in the other website :

    //Use it in the other
    $referer = '';
    if (isset($_SESSION['REFERER'])) {
        $referer = $_SESSION['REFERER'];
        unset($_SESSION['REFERER']);
    }
    

    You could also pass the referer as a parameter:

    header('Location: http://newurl.net?original_referer=' .$_SERVER['HTTP_REFERER']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示