【问题标题】:Receive Querystring and Redirect page接收查询字符串和重定向页面
【发布时间】:2016-10-18 11:15:58
【问题描述】:

如何获取名为“code”的 QueryString 并重定向包含该查询字符串的页面? 示例-

我会收到 mydomain.com/inteface.php?code=103103

我需要为 mydomain_new.com/interface.php?code=103103 重定向。

我知道 C#,但在这种情况下,我需要 php 中的这段代码来重定向到不同的服务器。

【问题讨论】:

标签: php redirect query-string


【解决方案1】:
header('Location:mydomain_new.com/interface.php?code='.$_GET['code']);

【讨论】:

    【解决方案2】:

    您可以使用名为$_GET$_SERVER 的超全局变量。您可以使用$_GET['code'] 从当前URL 中获取code 变量,并使用$_SERVER['HTTP_HOST'] 来获取域,如下所示:

            //Grab code from URL
            $code = $_GET['code'];
    
            //Grab current Domain Name being used
            $currentURL = $_SERVER['HTTP_HOST'];
    
            //Old Domain Name
            $oldDomain = "mydomain.com";
    
    
            //Read the header of the URL to test $domain is TRUE and $code has data
            if ($currentURL == $oldDomain && isset($code)) {
    
                     //Redirect to new domain using $_GET
                     header('Location: http://mydomain_new.com/interface.php?code=$code');//No need to concatenate single variable
    
            }
    

    见:

    http://php.net/manual/en/reserved.variables.get.php

    http://php.net/manual/en/reserved.variables.server.php

    【讨论】:

    • @EdilsonRafael 不用担心,很高兴它对你有用!
    猜你喜欢
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 2016-01-07
    • 2014-06-13
    • 2018-11-16
    • 1970-01-01
    • 2011-01-30
    相关资源
    最近更新 更多