View Single Post
Old 06-30-2008, 11:55 PM   #15 (permalink)
codefreek
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

THIS IS THE USER CODE


PHP Code:
<?php
error_reporting
(E_ALL & ~E_NOTICE);
include(
"db_connect.php");
session_start(); // Starts the session.

if ($_SESSION[‘logged’] == 1) { // User is already logged in.

        
header("Location: index.php"); // Goes to main page.

        
exit(); // Stops the rest of the script.

} else {

if ( ! isset(
$username))
{
    
$username '';
}

if ( ! isset(
$password))
{
    
$password '';
}

$szForm = <<<FORM
<form action="users.php" name="login" method="post"> 
<table> 
    <tr><td>username</td>
        <td><input type="text" name="username" value="
{$username}" /></td>
    </tr> 

    <tr><td>password</td>
        <td><input type="password" name="password" value="
{$password}" /></td>
    </tr>

    <tr><td colspan="2"><input type='submit' name='login' value='login' /></td></tr> 
</table> 
</form>
FORM;

echo 
$szForm;  
   
    


               
$password mysql_real_escape_string($_POST['password']);
           
$username mysql_real_escape_string($_POST['username']);




               

                
$q mysql_query("SELECT * FROM users WHERE username = '$username'
                 AND password = '
$password'") or die (mysql_error()); // mySQL query

                
$r mysql_num_rows($q); // Checks to see if anything is in the db.

               

                
if ($r == 1) { // There is something in the db. The username/password match up.

                        
$_SESSION[‘logged’] = 1// Sets the session.

                        
header("Location: index.php"); // Goes to main page.

                        
exit(); // Stops the rest of the script.

                
} else { // Invalid username/password.

                        
exit("Incorrect username/password!"); // Stops the script with an error message.

                
}

        }



?>
codefreek is offline  
Reply With Quote