+ Reply to Thread
Results 1 to 3 of 3

Thread: login system help

  1. #1
    brentcatoe is offline x10Hosting Member brentcatoe is an unknown quantity at this point
    Join Date
    Sep 2005
    Posts
    7

    login system help

    I am creating a login system for my site. I have the mysql database setup and I have the login script working. The problem is though when someone logs it still displays the login form, it is not supposed to. Here is my login script
    Code:
     
    <?
    $username = $_SESSION[‘uname’];
    if (!empty($username)) {
    			echo "Welcome You are Logged in as <b>". $_SESSION['username'] ."</b>";
    			$logout = "<a href=logout.php>Logout Here!</a>";
    }
    else { ?>
    <form action="checkuser.php" method="post" name="form1">
    Username:<br>
    <input name="username" type="text" id="username"><br>
    Password:<br>
    <input name="password" type="password" id="password"><br>
    <input type="checkbox" name="rememberme">Remember Me!<br>
    <input type="submit" name="Submit" value="Submit"><br>
    <? }
    if (!empty($username)) {
    echo "$logout";
    }
    else {
    echo "<a href=\"join_form.php\">Don't Have an Account?<br>Then Signup!</a></div>";
    }
    ?>
    and here is my checkuser.php file

    Code:
     
    <?
    /* Check User Script */
    session_start(); // Start Session
    include 'db.php';
    // Convert to simple variables
    $username = $_POST['username'];
    $password = $_POST['password'];
    if((!$username) || (!$password)){
    echo "Please enter ALL of the information! <br />";
    include 'index.php';
    exit();
    }
    // Convert password to md5 hash
    $password = md5($password);
    // check if the user info validates the db
    $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    foreach( $row AS $key => $val ){
    $key = stripslashes( $val ); 
    }
    $query = mysql_query( "SELECT * FROM users WHERE username=$username" );
    $result = mysql_fetch_array($query);
    // Register some session variables!
    session_register('email_address');
    $_SESSION['email_address'] = $email_address;
    session_register('username');
    $_SESSION['username'] = $username;
    session_register('level');
    $_SESSION['level'] = $result['user_level'];
     
    if (isset($_POST['rememberme'])) {
    setcookie ("uname", $username, time( ) + 99999999);
    setcookie ("email", $email_address, time( ) + 99999999);
    setcookie ("userlevel", $result['user_level'], time( ) + 99999999);
    }
    header("Location: /");
    }
    } else {
    echo "<b>You could not be logged in! Either the username and password do not match or you have not validated your membership through the email we sent you!
    Please try again!</b><br>";
    session_register('username');
    $_SESSION['username'] = "";
    setcookie ("uname", $username, time( ) - 1);
    include 'index.php/';
    }
    ?>
    does anyeone see any problems with that, I am stumped and cannot figure it out?

    Thanks

  2. #2
    vbchris's Avatar
    vbchris is offline x10Hosting Member vbchris is an unknown quantity at this point
    Join Date
    Feb 2005
    Location
    Belfast, N. Ireland, UK
    Posts
    90

    Re: login system help

    Try using this for the login code.

    PHP Code:

    <?
    $username 
    $_SESSION[‘uname’];
    if (!empty(
    $username)) {
                            echo 
    "Welcome You are Logged in as <b>"$_SESSION['username'] ."</b>";
                            
    $logout "<a href=logout.php>Logout Here!</a>";
    } else {
    echo 
    "<form action=\"checkuser.php\" method=\"post\" name=\"form1\">
    Username:<br>
    <input name=\"username\" type=\"text\" id=\"username\"><br>
    Password:<br>
    <input name=\"password\" type=\"password\" id=\"password\"><br>
    <input type=\"checkbox\" name=\"rememberme\">Remember Me!<br>
    <input type=\"submit\" name=\"Submit\" value=\"Submit\"><br>\n"
    ;
    }
    if (!empty(
    $username)) {
    echo 
    "$logout";
    }
    else {
    echo 
    "<a href=\"join_form.php\">Don't Have an Account?<br>Then Signup!</a></div>";
    }
    ?>
    Chris - Network-13


  3. #3
    chitwa is offline x10Hosting Member chitwa is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Kenya
    Posts
    64

    Re: login system help

    In your login form, you are checking for $_SESSION['uname'] while in checkuser.php, you set $_SESSION['username']. Solution: in your login script, check for $_SESSION['username']

+ Reply to Thread

Similar Threads

  1. Login
    By Tris10 in forum Free Hosting
    Replies: 8
    Last Post: 10-23-2006, 08:31 PM
  2. New PSP UPGADE
    By IamShipon1988 in forum Gamer's Lounge
    Replies: 4
    Last Post: 09-04-2005, 08:23 PM
  3. Safe Employee Login System?
    By NiMrOd in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 06-22-2005, 12:52 AM
  4. [PHP] MySQL Login System
    By BrettFreeman in forum Tutorials
    Replies: 15
    Last Post: 05-06-2005, 11:10 AM
  5. Cant see the site and login to cpanel
    By Jxwisniewski in forum Free Hosting
    Replies: 1
    Last Post: 04-05-2005, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers