+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP - Login Script

  1. #1
    nerdpowah23 is offline x10Hosting Member nerdpowah23 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    14

    PHP - Login Script

    This code below, should work properly, however I have no idea what I'm missing here, the else statement that says "Your info is incorrect..." which led me to believe that the query was messed up somehow, so I added an or trigger error on to it. Still no luck, can you help?
    Code:
    <?php require("styles/top.php");?>
    <?php
    $salt1 = "***********";
    $salt2 = "***********";
    ?>
       <?php
       if (isset($_POST['login-btn'])){
      $username = strip_tags($_POST['username']);
      $password = strip_tags($_POST['password']);
      
      if ($username && $password){
       
       $pass = $salt2.md5($password).$salt1;
       
       $query = mysql_query("SELECT * FROM farcry_crime_town.users WHERE username='$username' AND password='$pass'") or trigger_error('Error: ' . mysql_error());
       $numrows = mysql_num_rows($query);
       
       if ($numrows == 1){
        
        $row = mysql_fetch_assoc($query);
                        $dbid = $row['userid'];
                                    $dbuser = $row['username'];
                                    $locked = $row['locked'];
                                    $userlevel = $row['userlevel'];
                                    $total_logins = $row['total_logins'];
                                if($locked = 0){
        $new_total = $total_logins+1;
        $ip = $_SERVER['REMOTE_ADDR'];
        mysql_query("UPDATE farcry_crime_town.users SET last_login='NOW()', ip='$ip', total_logins='$new_total' WHERE userid='$dbid'");
        echo"<script type=\"text/javascript\">
                    window.location = \"index.php\"
        </script>";
        
        $_SESSION['username'] = $dbuser;
        $_SESSION['userid'] = $dbid;
        $_SESSION['userlevel'] = $userlevel;
        
     
        }
                    else
                       echo"<center><font color=\"red\">Your account is locked.</font></center>";
       }
       else
        echo "<center><font color=\"red\">Your login information was incorrect.</font></center>";
                              
      }
      else
       echo "<center><font color=\"red\">You did not fill in the entire form.</font></center>";
     }
     
     ?>
    <form action="login.php" method="post" enctype="multipart/form-data">
    <center>
    <table>
       <tr>
         <td>Username&nbsp;</td>
         <td><input type="text" name="username" class="textbox" /></td>
       </tr>
       <tr>
         <td>Password&nbsp;</td>
         <td><input type="password" name="password" class="textbox" /></td>
       </tr>
       <tr>
         <td><p class="login">
        <input name="login-btn" type="submit" class="btn" value="LOGIN" />
       </p></td>
       </tr>
    </table>
    </center>
    </form>
    </body>
    </html>

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP - Login Script

    Have it print out:

    $password
    $username
    md5($password)

    and then use PHPMyAdmin to check your database to make sure your stored values are correct.

    Usually I don't make the query an AND. I just ask for the info by username. Then compare stored and computed password hashes.
    Nothing is always absolutely so.

  3. #3
    nerdpowah23 is offline x10Hosting Member nerdpowah23 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    14

    Re: PHP - Login Script

    Works now, thanks!

+ Reply to Thread

Similar Threads

  1. login script
    By Chris Z in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-31-2012, 03:15 PM
  2. php login script
    By matt1213 in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 12-03-2008, 08:31 AM
  3. Need Login Script- Will pay
    By Conmiro in forum The Marketplace
    Replies: 4
    Last Post: 08-07-2008, 11:34 AM
  4. Login Script
    By taekwondokid42 in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 12-07-2007, 03:49 PM
  5. PHP login script
    By xunhandmex in forum Scripts & 3rd Party Apps
    Replies: 8
    Last Post: 05-26-2005, 07:56 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