我浏览了一百万个不同的网站,但似乎找不到答案——有没有办法从 cookie 中获取信息并将其放入数组中?我试过直接存储$_COOKIE['name']
到一个数组中,这会导致服务器错误。我试过存储$_COOKIE['name']
为 a $variable
,但是当我打印出数组时,它实际上只是返回$variable
. 成功做到这一点的人有什么智慧之言吗?
代码(除了实际的数组代码,整个页面都可以正常工作):
$productarray = array("$_COOKIE['gatq']"=>'The Great Gatsby <img src="gatsby.jpg">',
"$_COOKIE['catcherq']"=>'Catcher in the Rye <img src="catcher.jpg">',
"$_COOKIE['wavesq']"=>'The Waves <img src="waves.jpg">',
"$_COOKIE['strangerq']"=>'The Stranger <img src="stranger.jpg">',
"$_COOKIE['ulyssesq']"=>'Ulysses <img src="ulysses.jpg">',
"$_COOKIE['prideq']"=>'Pride and Prejudice <img src="pride.jpg">',
"$_COOKIE['mockingbirdq']"=>'To Kill a Mockingbird <img src="mockingbird.jpg">',
"$_COOKIE['roadq']"=>'On the Road <img src="road.jpg">'
);
if ($_COOKIE['fname'] == NULL or $_COOKIE['lname'] == NULL or $_COOKIE['address'] == NULL or $_COOKIE['city'] == NULL or $_COOKIE['state'] == NULL or $_COOKIE['zip'] == NULL)
{echo "<script language='javascript'>
window.alert('You left some information on the personal info page! You will be redirected.');
window.location.href='personal.php';</script>";
}
else
{
if ($_COOKIE['gatq'] == NULL &&
$_COOKIE['catcherq'] == NULL &&
$_COOKIE['wavesq'] == NULL &&
$_COOKIE['strangerq'] == NULL &&
$_COOKIE['ulyssesq'] == NULL &&
$_COOKIE['prideq'] == NULL &&
$_COOKIE['mockingbirdq'] == NULL &&
$_COOKIE['roadq'] == NULL)
{echo "<script language='javascript'>
window.alert('You don't have anything in your shopping cart! You will be redirected.');
window.location.href='inventory.php';</script>";
}
else
{
asort($productarray);
foreach ($productarray as $book=>$info)
{if ($book != NULL)
echo $book . "$info\n";
}
echo $productarray;
echo "testing";
}
}
?>
该错误只是说“服务器错误”,这与我遇到任何类型的语法错误时遇到的错误相同。