Results 1 to 4 of 4

Thread: code for logout page using sessions

  1. #1
    Join Date
    Feb 2010
    Posts
    21
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default code for logout page using sessions

    hiiiii

    i need a code for logout page using sessions or any other in php


    any suggestions are accepted...

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Completely depends on how you have your login set up / what sessions you use, but you could have:

    PHP Code:
    <?php

    if(isset($_GET['logout']) && $_GET['logout'] == 1) {
     unset(
    $_SESSION['login_details']);
    }

    ?>
    This would work if you had an array like:

    Array ( [login_details] => Array (
    [username] => 'Schmoopy'
    [name] => 'Jack'
    [more_stuff] => 'random'
    ) )

    etc..

    So it would get rid of all that information. So when you check for the "login_details" array, it won't be there, meaning the user is not logged in.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    zee000 (02-13-2010)

  4. #3
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Or if your using session_start();
    PHP Code:
    <?php
    //logout.php
    session_start();
    session_destroy();
    header("location: HOMEPAGE_GOES_HERE.php");
    ?>
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    But remember using session_destroy will get rid of all the session variables, so if you have any you want to keep hold of for a different part of the site, then use unset so you don't affect them.

Bookmarks

Posting Permissions

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