Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Question Unsetting Sessions/Cookies

    Hi all,

    I currently have a login area with the remember me features, this works fine but im having trouble getting the logout feature to work. I have set 2 cookies 'user_name' & 'password' and one session called 'loggedin'. I have tried the following code on a page called logout.php

    PHP Code:
    <?php
        session_start
    ();
        
        
    setcookie('user_name'''time()-60);
        
    setcookie('password'''time()-60);
            unset (
    $_SESSION['loggedin']);
                
    header("Location: http://www.mysite.com");
        exit();
    ?>
    But although the redirect works the user isnt logged out, which would suggest that the session and/or cookies are not being reset. Can anyone see why this may be the case?

    Thanks in advance

  • #2
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Dude... is that an html question? I think not. Try to look which forum this would best be posted in before you post it! I think this needs to be placed in the php forum. However, sdon't multipost... a nice moderator will move it for you.

    In answer to the question, to unset cookies you have to pasre them the exact same parameters that you set them with. To 'destroy' a session use:

    PHP Code:
        session_destroy(); 
    This is what I use:

    PHP Code:
            setcookie('Yourcookie''yours'time()-300''''0);
            
    $_SESSION = array();
            
    session_destroy(); 
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Appologies for posting in the wrong place:

    This is how i set the cookies:

    PHP Code:
    setcookie("clubviewnetwork[user_name]"$user_name$time 3600);
    setcookie("clubviewnetwork[password]"$password$time 3600); 
    This is how im trying to delete them:

    PHP Code:
    setcookie("clubviewnetwork[user_name]"""time()-3600);
    setcookie("clubviewnetwork[password]"""time()-3600); 
    As far as i can see they are parsed exactly the same way, but it still doesnt seem to want to remove them. I'm new to PHP so maybe im just missing something very obvious???

    The session was set like this:

    $_SESSION['loggedin'] = 1;

    I'm trying to remove the session with the following code:

    PHP Code:
    session_start();
    session_destroy(); 
    Could this be the reason the user remains logged in even after pressing the logout button?

    Thanks for the help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •