Hallo Leute!
Habe folgendes kleines Test-Script:
<?
if ($_COOKIE["TestCookie"] == "") {
$text = "Cookie off";
$title = "Start";
} else {
$text = "Cookie on";
$title = "Destroy";
}
if ($action == "on") {
setcookie ('TestCookie', 'Hallo',time()+60*60*24*30, '/','localhost');
$text = "Cookie on";
$title = "Destroy";
}
if ($action == "off") {
setcookie ("TestCookie", "", time() - 3600);
$text = "Cookie off";
$title = "Start";
}
if ($_COOKIE["TestCookie"] == "") {
echo $text;
echo "<br><form action="test1.php" method="post">\n";
echo "<input type="hidden" name="action" value="on">\n";
echo "<input type="submit" value=";
echo $title;
echo "></form>\n";
} else {
echo $text;
echo "<br><form action="test1.php" method="post">\n";
echo "<input type="hidden" name="action" value="off">\n";
echo "<input type="submit" value=";
echo $title;
echo "></form>\n";
}
?>
Nun funktionert es zwar so wie ich möchte, aber ich muss das Formular immer 2x abschicken, damit das Cookie gesetzt bzw. gelöscht wird.
Leider komme ich nicht dahinter, woran es liegt, dass es nicht beim ersten Klick klappt, sondern immer nen zweiten braucht.
Gruß, Jan