4

ランディング ページでユーザーをいずれかの場所に誘導できる Web サイトがあります。場所の選択を保存し、保存した情報に基づいて正しい場所にリダイレクトする方法があるかどうか疑問に思っています. 私はこれを以前に多くのストアページで見たことがあります. Cookie はこの情報を保存するための最良の方法でしょうか?

4

1 に答える 1

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']]);
}
于 2013-02-05T20:52:17.470 に答える