Viewing file: autorize.php (4.81 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
if (! isset($$cookie_name) )
{ $$cookie_name= -1; }
/******************************************************************************
* LOGIN FUNCTION: *
* *
* Parameters: *
* $v_user = username *
* $v_parola = password *
* *
* $rez=Login('admin','admin') *
* *
* Results: *
* $rez = -1 If Bad password *
* $rez = 0 If No such user *
* $rez = 1 If good user and password *
* *
******************************************************************************/
function Login($v_user, $v_parola)
{
global $cookie_name,$cookie_separ,$cookie_expire,$db_conect,$err_query;
global $REMOTE_ADDR, $HTTP_USER_AGENT, $Log_File;
$now = date("m, d Y, g:i a");
$v_parola=md5($v_parola);
$sql_txt="select password from client where user='$v_user'";
$sql_rez=mysql_query($sql_txt,$db_conect) or die ($err_query);
if (mysql_num_rows($sql_rez)<>0)
{
if ( mysql_result($sql_rez,0,'password')<>$v_parola )
{ return -1; exit; }
else
{
$sessid = uniqid(rand());
$timp = date('mdHi');
$ltimp = $timp + $cookie_expire;
$sql_txt = "delete from sesiuni where timp>$ltimp";
mysql_query($sql_txt,$db_conect) or die ($err_query);
$sql_txt="insert into sesiuni values('$sessid',$timp)";
mysql_query($sql_txt,$db_conect) or die ($err_query);
setcookie("$cookie_name",$v_user.$cookie_separ.$sessid);
$text="
$v_user - login:
IP: $REMOTE_ADDR
Date: $now
Browser: $HTTP_USER_AGENT";
$fp = fopen ($Log_File, "a");
fwrite($fp,$text);
fclose($fp);
return 1;
exit;
}
}
else
{ return 0; exit; }
}
/*****************************************************************************
* User is logged in ? *
* *
* $rez= E_Logat(); *
* *
* Result: *
* $rez = false Not logged in *
* $rez = true User is logged. *
* *
*****************************************************************************/
function E_Logat()
{
global $cookie_name,$$cookie_name,$cookie_separ,$cookie_expire,$db_conect,$err_query;
if ($$cookie_name=='-1')
{ return false; }
else
{
$SirCookie=explode($cookie_separ,$$cookie_name);
$sql_txt="select id, timp from sesiuni where id='$SirCookie[1]'";
$rez_sql=mysql_query($sql_txt,$db_conect) or die ($err_query);
if ( mysql_num_rows($rez_sql)<>0 )
{
$now=(int)(date('mdHi'));
$last=mysql_result($rez_sql,0,'timp');
$interval=$now-$last;
if ($interval>$cookie_expire)
{
$sql_txt="delete from sesiuni where id='$SirCookie[1]'";
mysql_query($sql_txt,$db_conect) or die ($err_query);
return false;
}
else
{
$sql_txt="update sesiuni set timp=$now where id='$SirCookie[1]'";
mysql_query($sql_txt,$db_conect) or die ($err_query);
return true;
}
}
else
{ return false; }
}
}
/*****************************************************************************
* Logout function. *
*****************************************************************************/
function logout()
{
global $cookie_name,$$cookie_name,$cookie_separ,$db_conect,$err_query;
global $REMOTE_ADDR, $HTTP_USER_AGENT, $Log_File;
if ($$cookie_name<>'-1')
{
$SirCookie=explode($cookie_separ,$$cookie_name);
$sql_txt="delete from sesiuni where id='$SirCookie[1]'";
$sql_rez=mysql_query($sql_txt,$db_conect) or die ($err_query);
$text="
$v_user - logout:
IP: $REMOTE_ADDR
Date: $now
Browser: $HTTP_USER_AGENT";
$fp = fopen ($Log_File, "a");
fwrite($fp,$text);
fclose($fp);
}
setcookie("$cookie_name");
}
/*****************************************************************************
* User Name: *
* *
* $rez=UserName(); *
* *
* Result: *
* $rez = '-1' If nobody is logged in *
* $rez = username if someone is logged in *
* *
*****************************************************************************/
function UserName()
{
global $cookie_name,$$cookie_name,$cookie_separ,$db_conect,$err_query;
if ($$cookie_name<>'-1')
{
$SirCookie=explode($cookie_separ,$$cookie_name);
return $SirCookie[0];
}
else
{ return -1;}
}
?>
|