dsgffz2579 2014-11-23 20:23
浏览 188

创建302重定向到动态更改的URL,并传递引用信息?

I want to redirect (302) my visitors of mydomain.com/page.php to another URL, that contains a dynamic value such as the visitor's IP address:

http://external.com/?ip=100.0.0.1

my common sense says this cannot be done with .htaccess, since the contents of it are static, and therefore the line would always be something like:

redirect 302 /redir-number-1 http://external.com/[not-useful-static-value]

Currently I'm first transferring the user to another PHP page (mydomain.com/transfer.php) with this redirection code:

$ip = $_SERVER['REMOTE_ADDR'] ;

$url = "http://external.com/?$ip;

header( "refresh:1;url=$url" );

But this doesn't seem to consist a 302 redirect, as the status code I get is 200, and it is also important for me to pass the original referring URL information (mydomain.com/page.php) when the visitor arrives to external.com, yet with my current method he arrives with mydomain.com/transfer.php as the referrer.

  • 写回答

2条回答 默认 最新

  • dshakcsq64956 2014-11-23 20:34
    关注

    Try this for a 302:

    header("Location: $url", true, 302);

    But you are never going to get the correct referrer on a redirect. You need to add it as a variable in the URL maybe.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程