接收查询字符串和重定向页面

Receive Querystring and Redirect page

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

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

我需要 mydomain_new.com/interface.php?code=103103.

的重定向

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

header('Location:mydomain_new.com/interface.php?code='.$_GET['code']);

您可以使用名为 $_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