Edilson Rafael
Edilson Rafael

Reputation: 35

Receive Querystring and Redirect page

How can I get a QueryString named "code" and redirect my page including the querystring? Example-

I'll receive mydomain.com/inteface.php?code=103103

I need redirect for mydomain_new.com/interface.php?code=103103.

I know C#, but in this case I will need this code in php for redirect in a different server.

Upvotes: 2

Views: 39

Answers (2)

Kitson88
Kitson88

Reputation: 2950

You can use the superglobals called $_GET & $_SERVER. You can use $_GET['code'] to grab the code variable from the current URL and $_SERVER['HTTP_HOST'] to grab the domain like this:

        //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

        }

See:

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

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

Upvotes: 0

Pradyut Manna
Pradyut Manna

Reputation: 588

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

Upvotes: 1

Related Questions