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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2010
    Location
    Regina, Saskatchewan, Canada
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    session isnt getting destroyed

    PHP Code:
    $errorMsg "";
    session_start();
    setcookie("id"''time()-3600*24*730"/");
    setcookie("idx"''time()-3600*24*730"/");
    setcookie("username"''time()-3600*24*730"/");
    setcookie("useremail"''time()-3600*24*730"/");
    setcookie("userpass"''time()-3600*24*730"/");
    setcookie("accounttype"''time()-3600*24*730"/");
    session_destroy();
    sleep(3); 
    if(!isset(
    $_SESSION['id'])){
        
    header("location: index.php");
        exit();
    } else {
        
    $errorMsg "Logout Error";

    When I try to logout it doesn't let me, it removes the cookies, the but session_destroy doesnt seem to get destroyed and I'm still logged in. The Logout Error message is displaying.

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    NY
    Posts
    33
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi,

    I am not an expert in php but i am learning php for last 4 months and have practiced many times on session's and cookies. As i have gone through your code i have seen that you are not creating session variable but instead your are creating cookies which cannot be deleted by session_destroy() method. As of this code you don't have any session variable so the condition is not getting satisfied and you are getting Logout error message.

    Instead of setcookies() you must use $_SESSION["id"]=$anyvariable; to get it worked. Hope it will help you. And no doubt i might be wrong but i am sure that i am not.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Try using unset():

    PHP Code:
    unset($_SESSION);
    session_destroy(); 
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    Philly100000 (04-14-2012)

  • #4
    New Coder
    Join Date
    Jun 2010
    Location
    Regina, Saskatchewan, Canada
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Try using unset():

    PHP Code:
    unset($_SESSION);
    session_destroy(); 
    The unset before the session_destroy fixed the problem, many thanks!


  •  

    Posting Permissions

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