【问题标题】:Redirect user to website based on stored cookie information根据存储的 cookie 信息将用户重定向到网站
【发布时间】:2013-01-20 22:01:58
【问题描述】:

我有一个网站,我的着陆页可以将用户带到我们的某个位置。我想知道是否有办法存储他们的位置选择并根据我存储的信息将它们重定向到正确的位置。我以前在很多商店页面上看到过这一点,他们保留并让您浏览本地商店。 cookie 是存储此信息的最佳方式吗?

【问题讨论】:

标签: php css html cookies


【解决方案1】:

Cookie 非常适合这种情况。只需记录位置 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']]);
}

【讨论】:

  • 你真棒又快!非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多