Page 1 of 1

!isset & request method = post, set cookie to 0?

Posted: Thu May 24, 2007 1:14 pm
by JAB Creations
Using...

Code: Select all

<form><fieldset><input name="chatroom" type="checkbox" value=1" />
The first part of the PHP seems to work. However to unset the option the user unchecks the input and the page is requested via a POST (because of the form) I'd like to set the cookie to a value of 0.

Code: Select all

if ($_POST['chatroom']=='1') {setcookie('chatroom','1',time()+2592000,'/');}
else if (isset($_REQUEST['post']) && !isset($_POST['chatroom'])) {setcookie('chatroom','0',time()+2592000,'/');}
What do I need to change?

Posted: Thu May 24, 2007 1:15 pm
by feyd
$_REQUEST['post'] doesn't exist, most likely.

$_SERVER['REQUEST_METHOD'] is what you're looking for.

Posted: Thu May 24, 2007 1:19 pm
by JAB Creations

Code: Select all

else if ($_SERVER['REQUEST_METHOD']=='POST' && !isset($_POST['chatroom'])) {setcookie('chatroom','0',time()+2592000,'/');}
Beautiful, thanks! :D