www.webdeveloper.com
Results 1 to 9 of 9

Thread: Log out code

  1. #1
    Join Date
    Dec 2006
    Posts
    8

    Exclamation Log out code

    My site has multiple users who can log in and out. I have a page titled 'logout.php' The code is listed below:
    PHP Code:
    <?PHP
       
    include_once("common.php");     
       include_once(
    "cookie.class.php");
       include_once(
    "users.class.php");
       
       
    session_destroy();
       
       
    $cookie = new Cookie();
       
    $cookie->delete_cookie('login');
       
    setcookie('SMFCookie10'NULLtime()-3600);
       
       
    header("Location: " URL_ABSOLUTE );
    ?>
    Currently with this code, when a user logs out they are directed to the homepage but I would like them to be directed to a thank you page that says they are logged out.

    Does anyone know how I can implement this using the code above?

    Thanks
    Last edited by LiLcRaZyFuZzY; 01-31-2007 at 12:26 PM.

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    header("Location: " URL_ABSOLUTE ); 
    Change the above to a page of your choice:
    PHP Code:
    header("Location: thankyou.php"); 

  3. #3
    Join Date
    Dec 2006
    Posts
    8
    Ok thanks...

    Is there a way to send different users to different thank you pages from the logout link?

    Here is the current code:

    <? if(isset($_SESSION['user'])) { ?>
    <a href="<?=URL_ABSOLUTE?>/logout2.php" style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Sure, you can make the redirection user-specific, to the extent that you're able to differentiate.

  5. #5
    Join Date
    Dec 2006
    Posts
    8
    Problem is... I dont know how to write the code very well...

    Here is a peice of code below: that I took from another link on the site. The code is based on the user type and ID. I would like to have the same type of thing happen with the logout but each user would be directed to a different page when they log out:

    <a href="<?=URL_ABSOLUTE?>/search.php?search=basic&type=2&category_id=<? echo $_SESSION['user']['category_id'];

    ?>&s=&submit=search"class="main_nav">INDUSTRY</a>

    How would I write the logout code?

  6. #6
    Join Date
    Dec 2006
    Posts
    8
    This code seemed to work but now when I am logging out with the user id=2, I see the orginal login as well. It should be gone.

    <? if($category_id == 2) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 2']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 2] :

    '/logout2.php'; ?> style="color: #FFF;">LOG OUT</a>
    <? endif; ?>

  7. #7
    Join Date
    Dec 2006
    Posts
    8
    Here is another thing I tried but didnt work.... Can anyone help??

    PHP Code:
    <? if($category_id == 1) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 1']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 1] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

    <? if($category_id == 2) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 2']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 2] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

    <? if($category_id == 3) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 3']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 3] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

    <? if($category_id == 4) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 4']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 4] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

    <? if($category_id == 5) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 5']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 5] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>

    <? if($category_id == 6) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 6']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 6] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>
                
    <? if($category_id == 7) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 7']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 7] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>


    <? if($category_id == 8) : ?>
    <a href="<?=URL_ABSOLUTE?><? echo isset($_SESSION['user']['category_id == 8']) ? '/logout2.phpid='.$_SESSION['user']['category_id' == 8] : 

    '/logout2.php'?> style="color: #FFF;">LOG OUT</a> /
    <? } else { ?>
    Last edited by LiLcRaZyFuZzY; 01-31-2007 at 12:27 PM.

  8. #8
    Join Date
    Dec 2006
    Posts
    8
    My question hasn't really been answered yet... Can anyone help?

  9. #9
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    if you want to redirect, use header() instead of "<a href="

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles