Page 1 of 1

Trying to use Cookies with Include()

Posted: Mon Aug 01, 2005 3:25 pm
by desinc
Hello. At the moment, I'm trying to have this file:

Code: Select all

<?php
if ($_COOKIE['slot1'] == 'none')
{
 $cookiesalreadyset = 1;
} else {
 setcookie ('slot1', 'none');
 setcookie ('slot2', 'none');
 setcookie ('slot3', 'none');
 setcookie ('slot4', 'none');
 setcookie ('slot5', 'none');
 setcookie ('slot6', 'none');
 setcookie ('slot7', 'none');
 setcookie ('slot8', 'none');
 setcookie ('slot9', 'none');
 setcookie ('slot10', 'none');
 setcookie ('all', 'none');
}

echo ('working'); //debugging
?>
Become called on a page using include(). However, on my pages, I get the 'working' text, yet cookies aren't set. I'm calling the function before any HTML. In short, I suppose I'm asking if cookies can be set using an included file, as that can be the only possible cause of this problem I can see at the moment. However, any help would be apprichated.

--- Luke

EDIT: Err... I suppose it's been said elsewhere on forums, but PHP tags ([php]) don't seem to be working.

Posted: Mon Aug 01, 2005 3:30 pm
by timvw
http://www.php.net/setcookie

Have a look at the common pitfalls..

Posted: Mon Aug 01, 2005 3:35 pm
by desinc
I've looked though that, and unless I'm missing something (which I proably am) I can't see anything relating to setting cookies from outside files.

--- Luke

Posted: Mon Aug 01, 2005 3:51 pm
by timvw

Code: Select all

if(!setcookie ('slot1', 'none')) echo 'problem';