问题
I want to allow traffic to my site only from a certain referring URL like "example.com/123". I want the rest of traffic to be redirected to the same referring URL after a particular delay, say 1 or 2 minutes. I want the traffic that comes from example.com/123 not to be referred anymore.
I thought of using something like this but I have no clue how to edit to meet my requirements:
<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/site1.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site2.html');
} else {
header('Location: http://www.customercare.com/home-page.html');
};
?>
回答1:
You'll need to have something in your php script that affect the header of the page, and not the header of the actual server response.
So in the part of the script that generates the header of your pages, you need something like this:
<!-- this is the header of your page -->
<head>
<title>Your Title</title>
<?php
$referrer = $_SERVER['HTTP_REFERER'];
// if referer isn't from example.com/123 we setup a redirect
if ( !strstr($referrer, '://example.com/123') )
print ('<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">\n');
?>
<!-- maybe some other stuff -->
</head>
So if the referer isn't from http://example.com/123
, then this line will be inserted into the header:
<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">
which tells the browser to redirect to the URL (in this case http://example.com/123
) after 60 seconds.
来源:https://stackoverflow.com/questions/19229923/how-to-redirect-and-or-delay-depending-on-referrer