2013-10-07 17 views
0

我想只允許來自某個推薦網址的流量訪問我的網站,如「example.com/123」。我想讓其餘的流量在延遲一段時間(例如1或2分鐘)後重定向到相同的引用URL。我希望來自example.com/123的流量 不再被引用。如何根據引用來重定向和/或延遲?

我想用這樣的事情,但我不知道如何修改,以滿足我的要求:

<?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'); 
}; 
?> 

回答

0

你需要在你的PHP腳本,影響頁的頁眉東西,而不是實際服務器響應的標題。

所以在生成網頁的標題腳本的一部分,你需要像這樣:

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

因此,如果引用者不是來自http://example.com/123,那麼這條線將被插入到報頭:

<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123"> 

它告訴瀏覽器重定向到URL(在這種情況下http://example.com/123)60秒後。