الفصل الثامن
236
البرنامج النصي login_track.php (تابع)
25.
$password = substr($password, 0, 8);
26.
$sql = "select * from users where username password = '$password'";
'$user' and
27.
if(!$result = mysql_query($sql)) {
28.
29.
}
30.
31.
32.
33.
34.
35.
36.
37.
failure();
if (mysql_num_rows ($result) == 1) {
setcookie("user", $user);
setcookie("password", $password);
trigger_error("VALID LOGIN", E_USER_NOTICE); return 1;
} else {
trigger_error("INVALID LOGIN", E_USER_NOTICE);
return 0;
38.
}
39.
}
40.
} //end check_user
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
function error_handler ($number, $string, $file, $line) {
global $admin_email;
$timestamp = date("m-d-Y H:i:s (T)");
switch($string) {
case ("INVALID LOGIN"):
global $user;
error_log("Failed login attempt by $user on $timestamp\n",3, "failed_logins.txt");
echo "<h3>Login Failed. Try Again!</h3>";
break;
case ("VALID LOGIN");
global $user, $REMOTE_ADDR, $HTTP_USER_AGENT;
error_log("LOGIN: $user on $timestamp from $REMOTE_ADDR using $HTTP_USER_AGENT\n",3,"valid_logins.txt");
break;
case ("DATABASE CONNECT ERROR"):
global $mysqlerr;
$message = "Database Error!\n";
58.
$message = "Unable to connect to database at
$timestamp\n\n";
ص٢٣٦