1

当人们访问我的网站时,我需要他们点击两个州(NC 或 VA)之一。根据单击的状态,它会将它们重定向到我网站上的相应页面。设置 cookie 后,我希望他们访问该站点,而不是再次询问问题,它已经知道将它们发送到他们选择的页面(状态)。我对 php 知之甚少...刚好够危险,您可以给我的任何方向将不胜感激。

4

3 回答 3

2

You can set the cookie as:

setcookie('state', $state, time() + (60 * 60 *24));

Assuming $state is either 'nc' or 'va', this will work:

if(isset($_COOKIE['state']))
{
    if($_COOKIE['state'] == 'va')
        header('Location: va/index.php');
    else if($_COOKIE['state'] == 'nc')
        header('Location: vnc/index.php');
}
else
{
    // Make them choose again here.
}
于 2012-06-07T15:41:51.147 回答
0

You should take a look at this php function setcookie.

setcookie( "state", "VA", time()+3600 );

Then redirect using the location header.

header( "Location: /" );
于 2012-06-07T15:41:56.227 回答
0

在索引页面上

<?php

if(isset($_COOKIE['state']))
{
   switch($_COOKIE['state'])
   {
      case "NC":
        header('location: www.url.com/site1/');
      break;

      case "VA":
        header('location: www.url.com/site2/');
      break;
   }

}
else
{
   //Display site options
}

?>

在各个网站上(例如 www.url.com/site1/):

<?php
if(!isset($_COOKIE['state']))
{
  setcookie('state', "NC" ,time() + (86400 * 7)); //valid for 7 days
}
?>
于 2012-06-07T15:43:39.977 回答