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>";
?>