Alens
Alens

Reputation: 11

Change referrer when redirecting

What I'm trying to do is use PHP to redirect from web site A to web site B (both are different domains), but I want the referrer in the HTTP headers to be set to web site A (the page that performed the redirect). So, that is, web site B will see web site A as a referrer.

Upvotes: 1

Views: 7539

Answers (3)

Domspan
Domspan

Reputation: 153

You can use something like <meta http-equiv="refresh" content="1;url=http://siteb.net"> on your site A.

Upvotes: 3

mauris
mauris

Reputation: 43619

I've checked using localhost and a dummy script. The browser does send the referer in the HTTP even at redirections.

To test this, I created a script called testRefererRedirect.php:

<?php

if($_GET['a']){

    if($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off'){

        echo $_SERVER['HTTP_REFERER'];

    }else{

        header('Location: https://localhost/testrefererredirect.php?a=1');

    }

}else{

    echo '<a href="testrefererredirect.php?a=1">test</a>';

}

To emulate cross domains, I used HTTP and HTTPS for my local server.

On first load, the page will show a link: I will click this link to allow the browser to send the referer in the headers. Next, because I load the page initially in HTTP the header function will be called. Finally, the HTTP referer header meant for the 2nd step showed up in the 3rd step.

Conclusion

You can safely use $_SERVER['HTTP_REFERER'] on website B to capture the refer information meant for website A if you do redirection on website A.

Upvotes: 0

user499054
user499054

Reputation:

I'm pretty certain that the sending the referrer is ultimately up to the web browser, not PHP. You could probably send the address via $_GET though.

Edit: You won't be able to change the referrer (misread the post, derp).

Upvotes: 1

Related Questions