我正在尝试编写一个调试脚本来测试我的 cookie,但由于某种原因,它总是运行脚本以删除所有 cookie,即使不满足条件也是如此。这是我的代码 - 都是 html 和 php:
<form id="cookietest" name="CookieTest" method="post">
<input type="submit" name="createcookie" value="Create cookie" />
<input type="submit" name="removecookie" value="Remove cookie" />
<input type="submit" name="removeallcookies" value="Remove all cookies" />
</form>
<?php
$Domain = thedomain.com
if($_POST['createcookie'] == TRUE)
{
$expire = 60*60*24*14 + time();
setcookie('TestCookie', 'IExist', $expire, '/', $Domain);
echo 'TestCookie should have been created. See its value below.<br />';
}
if($_POST['removecookie'] == TRUE)
{
$expire = time() - 60*60*24*14;
setcookie('TestCookie', 'IExist', $expire, '/', $Domain);
echo 'TestCookie should have been deleted. See its value below.<br />';
}
if($_POST['removeallcookies'] == TRUE);
{
$expire = time() - 60*60*24*14;
setcookie('TestCookie', 'IExist', $expire, '/', $Domain);
setcookie('Cookie1', '', $expire, '/', $Domain); // destroys persistent cookie
setcookie('Cookie2', '', $expire, '/', $Domain); // destroys persistent cookie
setcookie('Cookie3', '', $expire, '/', $Domain); // destroys persistent cookie
echo 'All specified cookies should have been removed. <br />';
}
if($_POST['createcookie'] == FALSE && $_POST['removecookie'] == FALSE)
{
echo 'Neither the cookie create nor cookie remove button was clicked.<br />';
}
echo "The contents of 'TestCookie':";
echo "${_COOKIE['TestCookie']}<br />";
echo "The cookie array<br />";
echo "<pre>";
print_r($_COOKIE);
echo "</pre>";
?>