Вы находитесь на странице: 1из 10

common.

inc
<?php
$DB_SERVER = "localhost"; // uuu
// Rofeufencko ure nuue f uuu
$DB_LOGN = "Marinet";
$DB_PASSWORD = "offfice"; // Ron nuue f uuu
$DB = "SRC"; // E uuu, c fnuuufe
// Rrefu u Web c
$HTTP_HOST = "192.168.10.18"; // HTTP xocf
// Rrefu u f uuu
$DB_TBL_USERS = "users"; // ure u fnuuf c nofeufenufe
$DB_TBL_MULT = "multi_data"; // ure u fnuuf, cxueuue u
uuufe of ureue "3nnue u RAM"
$DB_TBL_SNGLE="single_data"; // fnuu uuufe nu
euokfu nok
// Hre u ereuuun qn
$TMP_FLE = "dump.tmp";
?>
functions.php
<?php
require 'common.inc';
// Rok coeuue reuk
function DisplayErrMsg ( $message )
{
printf ("<blockquote><blockquote><blockquote><h3>
<font color=\'#cc0000\">%s</font></h3></blockquote>
</blockquote></bloackquote>\n", $message );
}
// Perucfu uo nofeufen cucferf
function registerUser ($user, $password, $password1, $fname, $lname)
{
global $DB_SERVER, $HTTP_HOST, $DB_LOGN, $DB_PASSWORD,
$DB, $DOCROOT;
if ( (strlen($user) < 4 ) || (strlen($password) < 5) || (strlen($password1) < 5) ||
( strlen($fname) < 2 ) || (strlen ($lname) < 2) ) return 0;
// uekoefuu xouu uuu
if ( strcmp($password, $password1) != 0) return -3; //
nonf ue e noeu koekfuo
$password = md5 ($password);
if (! ($link = mysql_pconnect ($DB_SERVER, $DB_LOGN, $DB_PASSWORD)))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return -1; // cucferu reuk
}
if ( !($result = mysql_db_query ( $DB, "SELECT * FROM users WHERE
name='$user'")))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return -1; // cucferu reuk
}
if ( mysql_fetch_row ($result) ) return -2; // ur ee erucfuu nofeufen
c fo ure!
if ( !($result = mysql_db_query ( $DB, "NSERT NTO users VALUES ('' ,'$user',
'$password', '$fname', '$lname')")))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return -1; // cucferu reuk
}
return 1; // nofeufenn e erucfuu ycneuuo
}
// Pnou nofeufenckun uueufuqukfo/non
// kfo nu noek fnuuf $DB_TBL_USERS
// Ako yonefonuefo e ycneuuo, qyukuunf true, ko ue, false.
function authenticateUser ( $user, $password)
{
global $DB_SERVER, $HTTP_HOST, $DB_LOGN, $DB_PASSWORD,
$DB, $DOCROOT;
// ue u nocfonuu k c MySQL c
if (! ($link = mysql_pconnect ($DB_SERVER, $DB_LOGN, $DB_PASSWORD)))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return 0;
}
// Heufuqukuun u nofeufenn
if ( !($result = mysql_db_query ( $DB, "SELECT * FROM users WHERE
name='$user'")))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return 0;
}
if (( $row = mysql_fetch_array ($result)) &&
( $password == $row["pass"] && $password !="")) return 1;
else return 0;
}
// B ureuf u nofeufenn
function getuserinfo ($user, &$user_id) {
global $DB;
if ( !($result = mysql_db_query ( $DB, "SELECT * FROM users WHERE
name='$user'")))
{
DisplayErrMsg (sprintf ("internal error %d:%s\n", mysql_errno(),
mysql_error()));
return 0;
}
$row = mysql_fetch_array ($result);
$ret = $row["first_name"]." ".$row["last_name"];
$user_id = $row["user_D"];
return $ret;
}
// Hfu cuku noreunuu u cecunf, koufo
// ce cxunf kfo uckufku (Cookies)
function deleteCookies ()
{
setcookie ("src_user");
setcookie ("src_pass");
}
login_form.htm
<html>
<head>
<title>LOGN</title>
<meta http-equiv="Content-Type" content="text/html; charset=SO-8859-1">
</head>
<body bgcolor="#EEEE99" text="#000000">
<br>
<table width="96%" border="0">
<tr>
<td width="4%" height="61">&nbsp;</td>
<td colspan="2" height="61"> <div align="center"><font size="3"><b> To use our
system resources you have to log in by using valid username and password
<br> f you are not registered click here
<a href="new_user.php" target="_self">fyk</a>! </b></font></div>
</td>
</tr>
<tr>
<td width="4%" height="66">&nbsp;</td>
<td colspan="2" height="66"></td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="67%"><form name="LoginForm" method="post" action="login.php">
<div align="right"><font size="4">Username:
<input type="text" name="form_user" maxlength="15" size="15">
<br><br></font> </div>
<div align="right"><font size="4">Password:
<input type="password" name="form_pass" size="15" maxlength="15">
<br><br><input type="submit" name="Submit" value=" Submit ">
</font> </div></form>
<br>
</td>
<td width="29%">&nbsp; </td>
</tr>
</table>
</body>
</html>
authenticated.htm
<html>
<head>
<title>Authentificated</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link rel="stylesheet" href="general.css" type="text/css">
</head>
<body bgcolor="#EEEE99" text="#000000">
<br><br><br><br><br>
<table align="center" width=70% border=1>
<tr align="center">
<td><br><font size="4">You are successfully log in "<b>
<?php echo $form_user; ?>"!</b></font><br><br><br><br>
</td>
</tr>
</table>
</body>
</html>
error_auth.htm
<html>
<head>
<title>Error authentification</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link rel="stylesheet" href="general.css" type="text/css">
</head>
<body bgcolor="#FFFF99" text="#000000">
<br><br><br><br><br>
<table align="center" width=80% border=3><tr align="center"><td>
<br><p class="error">You are not registered</p>
<br></td></tr></table>
<br><br><br><br><br>
<p align="center"><a href="login_form.htm" target="_self"><font
color="#000000"><br>Again</font></a></p>
</body>
</html>
login.php
<?php
require 'functions.php';
// ufu cuku cfu uckufku
deleteCookies();
// Roek u nofeufenn
$form_pass=md5($form_pass);
if (authenticateUser ($form_user, $form_pass))
{
// Bnuuocf u uckufkufe 30ruu.
setcookie ("src_user", $form_user, time() + 30*60);
setcookie ("src_pass", $form_pass, time() + 30*60);
include 'authenticated.htm';
exit ();
} else include 'error_auth.htm';
?>
new_user.php
<html>
<head>
<title>New user form</title>
<meta http-equiv="Content-Type" content="text/html; charset=SO-8859-1">
<link rel="stylesheet" href="general.css" type="text/css">
</head>
<body bgcolor="#EEEE99" text="#000000">
<?php
require 'functions.php';
if ( isset($form_flag) )
{
$res = registerUser (trim($new_user), trim($new_pass), trim($new_pass1),
trim($first_name), trim($last_name));
if ($res == 0) echo "<H1>The entered data is invalid</H1><hr
width=\"85%\">";
if ($res == -2) echo "<H1>Another user has this data</H1><hr
width=\"85%\">";
if ($res == -3) echo "<H1>Your password is wrong</H1><hr width=\"85%\">";
if ($res > 0)
{
echo "<p align=\"center\"><H2>Registration is successful<br><br>
exit ();
}
}
?>
<br><br><table align="center" width=70% border=0>
<tr><td>
<p align="center"><b><u>Please, enter the necessary information:</b></u></p><br>
<form name="UserForm" method="post" action="new_user.php">
<div align="right"><font size="4">Username:
<input type="text" name="new_user" maxlength="15" size="15">&nbsp; (ruu. 4
curon)&nbsp;<br><br></font></div>
<br><div align="right"><font size="4">Password:
<input type="password" name="new_pass" size="15" maxlength="15">&nbsp;
(ruu. 5 curon)&nbsp;<br><br></font></div>
<div align="right"><font size="4">Password (confirm):
<input type="password" name="new_pass1" size="15" maxlength="15">&nbsp;
(ruu. 5 curon)&nbsp;<br><br></font></div>
<br><br>
<div align="right"><font size="4">Name:
<input type="text" name="first_name" size="20" maxlength="20">&nbsp; (ruu. 2
curon)&nbsp;<br><br></font></div>
<div align="right"><font size="4">Family:
<input type="text" name="last_name" size="25" maxlength="25">&nbsp; (ruu. 2
curon)&nbsp;<br><br></font></div>
<input type="hidden" name="form_flag" value="yes">
<br><div align="right"><input type="submit" name="Submit" value="
Registration ">&nbsp&nbsp</div>
</form>
</td></tr></table>
</body>
</html>
checklogon.php
<?php
if (!authenticateUser ($src_user, $src_pass)) {
?>
<br><br><br><br><br><br>
<table align="center" width=70% border=2><tr align="center"><td>
<br><p class="error">
ATTENTON. You are not registered!
<br></td></tr></table>
<?php
exit();
}
?>

Вам также может понравиться