2013-02-05 26 views
4

我有一個網站,我的着陸頁可以將用戶發送到我們的某個位置。我想知道是否有方法存儲他們的位置選擇,並根據我存儲的信息將它們重定向到正確的位置。我之前在很多商店的網頁上看到過這些信息,並讓您瀏覽本地商店。 Cookie是否是存儲此信息的最佳方式?根據存儲的cookie信息將用戶重定向到網站

+0

http://php.net/setcookie –

回答

9

餅乾對於這種情況來說是完美的。只需記錄位置ID,然後下次重定向到該位置!

// store an array of location cookie names and there location values 
$places = array('us'=>'/united-states.php'); 

// After user chooses a location, store the cookie based on his choice: in this case, us! 
setcookie('location','us', time() + (3600 * 24 * 7)); 

// On a new page check the cookie is set, if it is then redirect users to the value of that cookie name in the array! 
if(isset($_COOKIE['location'])){ 
    header('Location: '.$places[$_COOKIE['location']]); 
} 
+0

你真棒,快!非常感謝! – user2044644

+0

@ user2044644我的榮幸! –