简体   繁体   中英

Redirect php using header location and passing parameters

so I'm using a redirect link for going from a landing page to an offer page, but in the middle, I want to go to a redirect page that is populated according to parameters I send, for example. my url is:

http://domain.com/file.php?param1={param1}&param2={param2}&param3={param3}&param4={param4}

and in file.php I will have the following:

<html><head>
     <script>
     function getURLParameter(name) {
         return decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] || ''
            );
        }
</script>
    <script>
    var param1 = getURLParameter('param1'); 
    var param2 = getURLParameter('param2');
    var param3 = getURLParameter('param3');
    var param4 = getURLParameter('param4');

    var url = 'http://domain2.com/'+param1+'?param2='+param2+'&param3='+param3+'&param4='+param4';

    window.location.replace(url);           
  </script>
</head>
<body>

</body></html>

now, I have been trying to use

header('Location: '.$newURL);

but I wasn´t able to make it work like that, the thing is that I would like to be able to manage the redirection to "domain2" seamsless, as in the middle I'm losing track of some information that I would like to have.

in the normal process of tracking url (domain.com) --> to destination url (domain2.com) there is no problem, the thing is that I need to add file.php in the middle (which is in another domain) because I have an script that needs to be executed only there.

thank you in advance

May be you can use usual $_GET to get the params from URL string? And then in php you can do anything you want. Like: http://domain.com/file.php?param1= {param1}&param2={param2}&param3={param3}&param4={param4}

in file.php:

$param1 = $_GET['param1'];

$param2 = $_GET['param2'];

and etc. Then you can set header function with needed options Hope that helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM