Results 1 to 2 of 2

Thread: [RESOLVED] Sessions Help Plz

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Sessions Help Plz

    Hello,

    Im beable to login with my code below.

    PHP Code:
    <?php 
    session_start
    ();
    require(
    "./styles/top.php");?>
       
    <p>Login</p>

        <?php
           
           $form 
    "<form action='login.php' method='post'>
           <table>
           <tr>
                <td>Username:</td>
                <td><input type='text' name='username'></td>
           </tr>
                <td>Password:</td>
                <td><input type='password' name='password'></td>
           </tr>
           </tr>
                <td></td>
                <td><input type='submit' name='loginbtn' value='Login'></td>
           </tr>
           </table>
           </form>"

           
           if(
    $_POST['loginbtn']){
                
    $username strip_tags($_POST['username']);
                
    $password strip_tags($_POST['password']);
                
                if (
    $username && $password){
                    
                    require(
    "includes/connect.php");
                    
                    
    $pass md5(md5($password));
                    
                    
    $query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$pass'");
                    
    $numrows mysql_num_rows($query);
                    
                    if (
    $numrows == 1){
                        
                        
    $row mysql_fetch_assoc($query);
                        
    $dbid $row['id'];
                        
    $dbuser $row['username'];
                        
                        
    $_SESSION['user_name'] = $dbuser;
                        
    $_SESSION['userid'] = $dbid;
                        
                        echo 
    "You have been logged in as <b>$dbuser</b>.";
                        
                    }
                    else
                        echo 
    "Your login information was incorrect. $form";
                    
                }
                else
                    echo 
    "You did not fill in the entire form. $form";
           }
           else
                echo 
    "$form";

        
    ?>


         
    <?php require("./styles/bottom.php");?>
    But when I try to logout it keeps showing this message even though im logged in.

    No user was logged in.

    PHP Code:
    <?php 

    session_start
    ();

    $user_name $_SESSION['username'];

    require(
    "./styles/top.php");?>
       
    <p>Logout</p>

    <?php

    if ($user_name){
        
    session_destroy();
        echo 
    "<b>$user_name</b> has been logged out";
    }
    else
        echo 
    "No user was logged in.";

    ?>


         
    <?php require("./styles/bottom.php");?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,529

    Re: Sessions Help Plz

    You are setting the session as "user_name" and you are getting the session as "username"

Posting Permissions

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



Click Here to Expand Forum to Full Width