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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_REQUEST['post'] doesn't exist, most likely.

$_SERVER['REQUEST_METHOD'] is what you're looking for.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Code: Select all

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