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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Showing Admin Links

    Hi the following is my login code, when you login it shows links instead of the login box, and when you logout the login box shows instead of the links.

    If i were to be a certain user then extra links will show.

    The problem is, is that the links show for the certain user but when you logout they still show, How would i be able to make it so the extra links appear for a certain user and dissapear when they log out???

    PHP Code:
    <?php 
    if(@$_SESSION['Loggedin'] == 'true'){

    ?>

    LOGIN STUFF HERE!

    <?php
    }else { 
    @
    $_SESSION['Loggedin'] = 'false';
    $_SESSION['admin'] = 'false'
    ?>

    <?php 
    $_SESSION
    ['incorrect_login']='false';
    if (
    $_SESSION['incorrect_login'] =='true')
    {echo
    "Incorrect username or password";}
    ?>

    <form action="user_logged_in.php" method="post">

    Username:<br> <input type="text" name="loginname" size="19"><br>
    Password: <br><input type="password" name="password" size="19"><br>
    <br><input type="Submit" value="Login">
    </form>

    <span class="main_class">
    <a href="register.php">Register</a><br>
    <a href="link">Forgot Password?</a><br>
    </span>

    <?php ?>

    STUFF HERE

    <?php

    if (@$_SESSION['loginname'] == 'USERNAME HERE'){
    $_SESSION['admin'] = 'true';}
    else{
    $_SESSION['admin'] = 'false';}

    if (
    $_SESSION['admin'] == 'true'){ ?>

    ADMIN STUFF HERE!

    <?php ;} ?>

    My Logout code:

    PHP Code:
    <?php session_start();

    $_SESSION['Loggedin'] = 'false';

    $_SESSION['admin'] = 'false';

    header("location:index.php");

    ?>
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    when you log out you set loggedin and admin to false, however your script sets 'admin' status based on whether the username is set to a given value, so if I log in as an admin, then logout, my admin status is set to false. But the script checks to see if my username is an admin - it resets the admin status to true.

    Unless you're keeping data in the session that doesnt require users to be logged in. Use session_destroy() to logout users

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey thanks for that, it worked!!!!
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.


  •  

    Posting Permissions

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