Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-11-2005, 11:30 AM Ending a Cookie
Manson's Avatar
Super Talker

Posts: 106
Location: South Wales, UK
Trades: 0
Hey all. I have a cookie being set when a user logs in and when they logout the cookie is supposed to be ended.

Here is the start (login):

PHP Code:
//Collect the details and validate 
    
$time time();  
    
$pass md5($password);  
    
$sql mysql_query("SELECT * FROM members WHERE username='$username' AND password='$password'") or die(mysql_error()); 
    
$count mysql_num_rows($sql); 
     
    if (
$count 0
    { 
        
$cookie_data $username.'-'.$pass;   

    
setcookie ("cookie_info",$cookie_data$time+1800); 

    
header("Location: home.php"); 
And the end (logout):

PHP Code:
<?php 
$time 
time(); 

if (isset(
$_COOKIE['cookie_info'])) 

  
setcookie ("cookie_info"""$time 1800);
?>
<font face="Verdana" size="2" color="FF0000"><?php echo "Logged Out"?></font> 
<?php

?>
I got this from phpfreaks.com when I first started learning php. But the cookie doesn't seem to end and doesn't log out th user.

Anyone able to help?

Thanks in advance,

Manson
__________________
Admin of
Please login or register to view this content. Registration is FREE
Manson is offline
Reply With Quote
View Public Profile Visit Manson's homepage!
 
 
Register now for full access!
Old 03-11-2005, 02:37 PM
Buddha443556's Avatar
Novice Talker

Posts: 10
Trades: 0
Common problems for cookies which I think may apply here:
  1. Set cookie in doc root and trying to delete it from a sub directory.
    SOLUTION: Use path argument:
    setcookie ("cookie_info", "", $time + 1800, "/");

  2. Clocks off. Server clock and client clock not in sync. Very common. Do to this it is very hard to use short lived cookie without implement a sessions type solution.
    SOLUTION: Use really big difference like 24+ hours when deleting:
    setcookie ("cookie_info", "", 1, "/");

Some browser just don't handle cookies very well like IE 4.x or late Netscape 4.X.
Buddha443556 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Ending a Cookie
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39125 seconds with 12 queries