Missing HTTP Referrer info on IE/FF (works well on

2019-08-10 07:04发布

问题:

I have page1.php with this code:

<form action="/redirect.php" method="POST" target="_blank">
<input name="destination" type="hidden" value="a"/>
<input type="submit" value="Click here"></form>

and this is redirect.php:

<?php

$url = "http://www.default.com"; 

if(isset($_POST['destination'])){

    switch ($_POST['destination']) {

    case "a":
        $url = "http://www.domain1.com";
        break;

    case "b":
        $url = "http://www.domain2.com";
        break;

    default:
        $url = "http://www.default.com";
    }
}

header( "refresh:1;url=$url" );

?>  
<!doctype html>
<html>
<head>
</head>
<body>
<div>Redirecting, Please wait</div>
</body>
</html>

I've created the redirect page this way because it's important for me that it would load and display certain content, rather than redirect straight away (and thus, it yields out a 200 code, rather than a 302 code).

However, only on Chrome and Safari, the Headers of the redirect contain information about the referring url, which is redirect.php, and thus, for example, the owner of domain1.com will know that the visitor came from mydomain.com/redirect.php.

But on IE and FF, the referrer in the headers is null. What is causing this different behavior and how can I fix it to have them carry the same referrer info as well?

回答1:

You may try:

header("Location: ".$url."");


回答2:

Working example (tried on FF 27.0.1):

File page1.php:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Starting page</title>
</head>
<body>
<form action="redirect.php" method="post">
    <input type="hidden" name="destination" value="a">
    <input type="submit" value="Click here">
</form>
</body>
</html>

File redirect.php:

<?php

$url = "http://www.default.com"; 

if(isset($_POST['destination'])){

    switch ($_POST['destination']) {

    case "a":
        $url = "http://www.domain.com";
        break;

    case "b":
        $url = "http://www.examples.com";
        break;

    default:
        $url = "http://www.example.com";
    }
}

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Landing page</title>
</head>
<body>
<div>Redirecting, Please wait</div>
<script>
window.onload = function() {
    setTimeout(function(){
        window.location = '<?php echo $url;?>';
    }, 4000);
};
</script>
</body>
</html>

How it's working: After clicking the button Click here on page1.php, the post data is sent and the domain http://www.domain.com is chosen. With javascript, after 4 seconds after window onload, the browser will redirect the user to http://www.domain.com. I have watched the referer headers in Firebug and they were sent.



回答3:

Confused. Redirect and page refresh is not equally. And more - not all browsers support refresh header.