SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Admin and non admin login

    I am a newbie to php and have a issue. I have a login code but i need the code to when admin login it sends then to a page with the admin menu bar. When a non admin login it sends them to the same page but with the non admin menu bar.

    I have a users table called "teams" with a column name "role" and 1 as admin and 2 as non admin...

    Here is my whole login code. Each member has a id so id # 3,15,17 are admin id's and 1,2,4,5,6,7,8,9,10,11,12,3,14,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31 are non admin id;s.. Can anyone help with this code??? Ive tried this ive tried that and i just cant seem to get the dam thing right.

    Here is the code:

    PHP Code:
    <?php  
    if(isset($_COOKIE['logged']))  
    {  
    ?>  
    <div id='signin'>  

        <form action="http://www.virtualhockeyassociation.com/onlogout.php" method="post" name="logForm" id="logForm" >  
            Welcome <?php session_start(); echo $_SESSION['GM'];?>!  
            <input type="submit" value="Log Out" />  
        </form>  
    </div>  
    <?php  
    }  
    if(isset(
    $_POST['doLogin']))  
    {  
    $email=$_POST['usr_email'];  
    $password=$_POST['pwd'];  
    if(
    file_exists('php_classes/config.php'))  
        include_once 
    'php_classes/config.php';  
    else  
        include_once 
    '../php_classes/config.php';  
    mysql_connect($dbhost,$dbuser,$dbpass);  
    mysql_select_db($dbname);  
    echo 
    "SELECT * FROM teams where email='$email' and password='$password'";  
    $result mysql_query("SELECT * FROM teams where email='$email' and password='$password'");  
    mysql_close();  
    if(
    mysql_num_rows($result) >0)  
    {  
        
    session_start();  
        
    $row=mysql_fetch_array($result);  
        
    setcookie('logged',$row['id'],time()+1000);  
        
    $_SESSION['uid']=$row['id'];  
        
    $_SESSION['GM']=$row['GM'];  
        
    $_SESSION['tid']=$row['newsid'];  
        
    $_SESSION['teamname']=$row['teamname_l'];  
        
    $_SESSION['teamabr']=$row['teamabr'];  
        
    header("location: http://www.virtualhockeyassociation.com/teams/teampage_admin.php?id=".$_SESSION['tid']); 
    }  
    else  
    {  
        
    header("location: http://www.virtualhockeyassociation.com/index.php?status=loginerror");  
    }  
    }  
    ?>  
    <div id='signin'>  
                    <form action="http://www.virtualhockeyassociation.com/signin.php" method="post" name="logForm" id="logForm" >  
                        <label class='loginLBL' for='username'>USERNAME:</label><input name="usr_email" type="text" class="required" id="txtbox" size="20">  
                        <label class='loginLBL' for='password'>PASSWORD:</label><input name="pwd" type="password" class="required password" id="txtbox" size="25">  
                        <input name="doLogin" type="submit" id="doLogin3" value="Login">  
                    </form>  
                </div>
    It has to easy. Im missing something but my php verbal knowledge isnt where it needs to be. Im a disabled vet and have taught all i know myself by reading and reading. Problem is part of my disability is a mental, memory thing... Anyway if anyone could show me how and what im doing wrong i would be very greatfull.

    Thank you and god bless

    ~Scott

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    How does the system know which users are admins and which ones arent? $_SESSION['GM'] ?

    PS: This line will not work:
    Code:
            Welcome <?php session_start(); echo $_SESSION['GM'];?>!
    session_start must be called before any output is made. Make it your first line of code. (Sessions should be started regardless of whether a user is signed in or not.)

    EDIT: Wow, okay i cant read apparantly. Go me. So commit $_SESSION['role'] to the record, and then if($_SESSION['role'] == 1) { serve admin bar } else { serve non-admin bar }
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh.. thank you sir. That did the trick.


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
  •