/var/www/enzatesting.onesolution.hk/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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
$formid 
"login";
require_once 
"inc/configure.php";

if( empty(
$_POST['name']) || empty($_POST['p']) ){
    
header('Location: loginform.php');
    exit;
}


//ip checking
$sql "SELECT
        count(*) as cnt
        FROM
        dbo.sys_elog
        WHERE
        dbo.sys_elog.tag = 'Login Failed' AND
        dbo.sys_elog.t > DATEADD(DAY, -1, GETDATE()) AND
        dbo.sys_elog.ipaddress = :ipaddress"
;        
$sth $dbh->prepare($sql);
$sth->execute( array(':ipaddress'=>getRealIpAddr()) );
//echo $sth->getSQL( array(':ipaddress'=>getRealIpAddr()) );
$row1 $sth->fetch();

//vdump($row1);
if( $row1['cnt']>10 ){
    
myerror('Too many retry - '.getRealIpAddr());
    exit;    
}

//exit;

session_start();
$sql "SELECT * FROM master_user WHERE userid=:userid AND userpwd=:password AND status=:status AND canlogin=1";        
$sth $dbh->prepare($sql);
$sth->execute( array(':userid'=>$_POST['name'], ':password'=>md5salt($_POST['p']), ':status'=>'ACTIVE') );
//echo $sth->getSQL( array(':userid'=>$_POST['name'], ':password'=>md5salt($_POST['p']), ':status'=>'ACTIVE') );
if($row $sth->fetch()){
    
$_SESSION['token']        = md5salt($row['createdate']); //security token
    
$_SESSION['refid']         = $row['refid'];
    
$_SESSION['xuser']         = $row['userid']; //login
    
$_SESSION['user']         = $row['userid']; //login
    
$_SESSION['username']    = $row['username']; //user name    
    
$_SESSION['companyid']     = $system_var['COMPANY_FACTORY']; //for getseccontent
    
$_SESSION['defaultcompany']     = $row['companyid']; //for ui default setting
    
    
if(!empty($_POST['language'])){
        
$_SESSION['lang']         = $_POST['language'];
    }
    else{
        
$_SESSION['lang']         = $row['lang'];
    }
    
//vdump($_SESSION['lang']); exit;
    
    
$_SESSION['role']         = 1
    
//echo "success";
    //vdump($_SESSION);
    //exit;
    
header('Location: main.php');
    exit;
}
else{
    
//echo"fail";
    //debug_print_backtrace();
    
adderrorlog("Login Failed");
    
header('Location: loginform.php?msg=Login+Failed');
    exit;    
}

?>