<?php
ob_start();
session_start();
include_once('config/koneksi2.php');
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$ids = $_POST['id'];

$qry = "SELECT * FROM tab_user WHERE username='$username' AND password='$password'";
$res = mysql_query($qry);
$num_row = mysql_num_rows($res);
$row=mysql_fetch_array($res);

if($num_row > 0) {
	$_SESSION['username'] = $row['username'];
	$_SESSION['password'] = $row['password'];
	$_SESSION['user_nama'] = $row['user_nama'];
	$_SESSION['nama_toko'] = $row['nama_toko'];
	$_SESSION['alamat_toko'] = $row['alamat_toko'];
	$_SESSION['user_akses'] = $row['user_akses'];
    $_SESSION['email'] = $row['email'];
    $_SESSION['region'] = $row['region'];

    		//$username=$_SESSION['username'];
            //$password=$_SESSION['password'];
            
            $_SESSION['username']=$username;
            $_SESSION['password']=$password;

        setcookie('username', $row['username'], time() + 1*24*60*60);
        setcookie('password', $row['password'], time() + 1*24*60*60);

   $a=mysql_query("select firtslogmo from tab_user where firtslogmo !='0000-00-00' and username='$username'");
    $b = mysql_num_rows($a);
    
    if($b < 1) 
    {
        $date = date('Y-m-d');
        $update=mysql_query("update tab_user set firtslogmo='$date', id_signal='$ids' where username='$username'");
    }
    else
    {
    $date = date('Y-m-d H:i:s');
    $update=mysql_query("update tab_user set lastlogmo='$date', id_signal='$ids' where username='$username'");
    }
    	echo 'true';
	}
	
else {
   
	echo'false';
}
ob_end_flush();
?>
<?php
/*session_start();
include_once('koneksi2.php');
//$message=array();
if(isset($_POST['username']) && !empty($_POST['username'])){
    $username=mysql_real_escape_string($_POST['username']);
}else{
    $message[]='Please enter username';
}

if(isset($_POST['password']) && !empty($_POST['password'])){
    $password=mysql_real_escape_string($_POST['password']);
}else{
    $message[]='Please enter password';
}

$countError=count($message);
$ids=$_POST['id'];
if($countError > 0){
     for($i=0;$i<$countError;$i++){
              echo ucwords($message[$i]).'<br/><br/>';
     }
}else{
    $query="select * from tab_user where username='$username' and password='$password'";

    $res=mysql_query($query);
    $checkUser=mysql_num_rows($res);
    $row=mysql_fetch_array($res);
    
    if($checkUser > 0){
         /*$_SESSION['LOGIN_STATUS']=true;*/
         
         
         /*$_SESSION['username']=$username;
         $_SESSION['password']=$password;
         
         setcookie('username', $row['username'], time() + 1*24*60*60);
         setcookie('password', $row['password'], time() + 1*24*60*60);
    $update=mysql_query("update tab_user set id_signal='$ids' where username='$username'");

          echo 'true';
          

    }else{
         echo ucwords('please enter correct user details');
    }
     
}*/

?>



