SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: logging out

  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    logging out

    Hi,

    How would i place the log out link in every pages just when the user has logged in?

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by runrunforest View Post
    Hi,

    How would i place the log out link in every pages just when the user has logged in?
    It depends how you implement your authentication system. Is there a session variable telling if the user is logged in? If so, then check if the variable is set and if it is then display a log out link. If it's not then display a log in link.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is session variable.

    I know the logic of doing this, just the actual technique is unknown.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sure, something like this should do it.

    PHP Code:
    //--> Anywhere on page.
    <?php
    session_start
    ();
    if(
    $_SESSION['auth']['loggedIn'] == true){
        echo 
    '<a href="http://www.yourserver.com/logOut.php" title="Log Out">Log Out</a>';
    }
    ?>

    //--> logOut.php
    <?php
    session_start
    ();
    if(isset(
    $_SESSION['auth']))
    {
        unset(
    $_SESSION['auth']);
    }
    header('Location: http://www.yourserver.com/');
    exit;
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about logout link? I need the link to be available in every pages.

    This probably involves some css, isn't it ?

    Further more, I need the link to disappear as long as user logged out

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The logout link will only show if the user is logged in, just place the top bit of code on each page/template you want the logout link to be displayed.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure if this is anymore any help but ill post it anyway in case op wanted to see how the link is handled using eg. GET method.

    PHP Code:
    // The link and when clicked it will set variable called $_GET['logout']
    echo '<a href="http://www.yourserver.com/'$_SERVER['SCRIPT_NAME'] .'?logout">Logout</a>';

    // And then you check if $_GET['logout'] is set or not and if yes you set your 
    // logout/auth variable to something that you use to check if user is logged or not.
    if (isset($_GET['logout']))
    {
        
    $_SESSION['logged'] = false;

    $_SERVER['SCRIPT_NAME'] references to the page you are at the current moment. And CSS has nothing to do with making logout/login script in php.

  8. #8
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    The logout link will only show if the user is logged in, just place the top bit of code on each page/template you want the logout link to be displayed.
    I put the echo in tamplate, it shows up even user didnt log in. Though i have set the condition like this and put it on the top of template.
    <?php session_start(); ?>
    <?php if(isset($_SESSION['email')) {} ?>


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
  •