Trying to use Cookies with Include()

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
desinc
Forum Newbie
Posts: 16
Joined: Sat Jan 31, 2004 5:13 pm

Trying to use Cookies with Include()

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http://www.php.net/setcookie

Have a look at the common pitfalls..
desinc
Forum Newbie
Posts: 16
Joined: Sat Jan 31, 2004 5:13 pm

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

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