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 5 of 5

Thread: session destroy

  1. #1
    New Coder
    Join Date
    May 2010
    Location
    Mexico
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    session destroy

    Hi i'm trying to logout from a session but the $_SESSION['user'] shows the same even if i try with another registered user

    this is where i do the login

    username1: Alex password:adacosta
    username2:Raquel password adacosta01

    my logout.php is like this:

    PHP Code:
    <?php
    //empieza sesion
    session_start();

    //nos aseguramos que la variable esté registrada
    if(session_is_registered('usuario')){

    //la variable de sesion esta registrada, procedemos a destriur la sesion
    session_unset();
    session_destroy();

    }
    else{


    echo
    "no se puede terminar la sesión correctamente"
    }
    ?>
    i can't find out what could be wrong

    thanks a lot
    Lo bueno del cine es que durante dos horas los problemas son de otros.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Do you need to clear all sessions? Check out the user comments for it:
    http://us3.php.net/session_unset

    Else just unset the session you need to clear:
    unset($_SESSION['yourVar']);

    Good luck

  • #3
    New Coder
    Join Date
    May 2010
    Location
    Mexico
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks a lot i'll try that =)
    Lo bueno del cine es que durante dos horas los problemas son de otros.

  • #4
    New Coder
    Join Date
    May 2010
    Location
    Mexico
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i made the user name change but i still can´t make the logout button work....

    this is what i got:

    PHP Code:
    <?php

    //start the session
    session_start();

    //check to make sure the session variable is registered
    if(session_is_registered('usuario')){

    //the session variable is registered, the user is allowed to see anything that follows

    $id=session_id();
    echo 
    "Bienvenido,".$_SESSION['usuario']." Sigues Dentro yuju!!!, tu id de sesion es:".$id;

    }
    else{

    //the session variable isn't registered, send them back to the login page
    header"Location: http://www.adconsulting.mx/adacosta/pruebas_php/login.php" );
    }
    echo
    "
    <form>
    <input type=\"submit\" value=\"Logout\" action=\"logout.php\" target=\"login.php\">
    </form>
    "
    ;
    ?>
    and the logout.php:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION = array();
    session_destroy();
    session_regenerate_id();  
    header"Location: login.php" );  
    ?>
    thanks!
    Lo bueno del cine es que durante dos horas los problemas son de otros.

  • #5
    New Coder
    Join Date
    May 2010
    Location
    Mexico
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok ok!! i found it ... i was writing the form attributes to the <input type> tag... never mind thank anyway!
    Lo bueno del cine es que durante dos horas los problemas son de otros.


  •  

    Posting Permissions

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