/
login.php
47 lines (38 loc) · 1.17 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/* File: login.php
Desciption: Implementation file to log users into the system.
Author: Eric A. Bonney
Date: September 24, 2009
Updated:
*/
require_once "includes/authentication.inc";
require_once "includes/db.inc";
// Get a connection to the database.
if( !($connection = @mysql_connect( $hostName, $username, $password ) ) )
die( "Could not connect to database" );
// Now that we are connected, select the correct database.
if( !mysql_select_db( $databaseName, $connection ) )
showerror();
$user_name = mysqlclean($_POST, "username", 25, $connection);
$pass1 = mysqlclean($_POST, "password", 16, $connection);
session_start();
// Authenticate the user.
if( authenticateUser( $connection, $user_name, $pass1 ) )
{
//Register the username
$_SESSION["loggedinUserName"] = $user_name;
//Register the current IP address of the user.
$_SESSION["loginIP"] = $_SERVER["REMOTE_ADDR"];
// Send the user to the Dashboard.
header( "Location: dashboard.php");
exit;
}
else
{
//Authentication failed, setup a logout message
$_SESSION["message"] = "Could not login as '{$user_name}'";
// Send user to the logout page.
header( "Location: logout.php" );
exit;
}
?>