COOKIES!

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
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

COOKIES!

Post by s.dot »

I have a PHP chat programmed, and it reads the value of a username stored in a cookie ( $_COOKIE['username'] :o ). Now my problem is, when they open another window, with the chat left open, and log out of my site in that window, they are left with a " " (blank) username in the chat.

So to solve this, I tried checking to see if the cookie isn't set, or if the cookie username == "" when they post a message, and attempt to redirect them to the login screen. Neither worked.

How could I solve this problem?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You should be able to check if a cookie is set and what the value is. Try print_r($_COOKIE) to debug.

You might also want to consider using different cookies for different purposes. If you have a separate cookie for the chat area, it won't be deleted when they logout somewhere else.

Sessions are also worth a look.
Post Reply