<?php 
//date_default_timezone_set('Asia/Kolkata');
  @session_start(); error_reporting(0); 
class DBController {
	private $host = "localhost";
    private $user = "u840064903_amjad";
    private $password = "Amjad#@#@143";
    private $database = "u840064903_amjad";
	private $connection = "";
	
	function __construct() {
		$conn = $this->connectDB();
		$this->connection = $conn;
	}
	
	function connectDB() {
		$conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
		return $conn;
	}
	
	function runQuery($query) { $resultset;
		$result = mysqli_query($this->connection,$query);
		while($row=mysqli_fetch_assoc($result)) {
			$resultset[] = $row; 
		} 		
		if(!empty($resultset)) return $resultset; 
	}
	
	function numRows($query) {
		$result  = mysqli_query($this->connection,$query);
		$rowcount = mysqli_num_rows($result);
		return $rowcount;	
	}
}
//phpinfo();
$getData = new DBController();
$db_handle = new DBController();
$date = date('Y-m-d G:i:s');
$idate=date('ymdhis');
 $ip = '';
 if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
    {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //if from a proxy
    {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
session_regenerate_id(true);
// $baseurl='https://www.umeedeinfoundation.org/c_panel/';
// $homeurl='https://www.umeedeinfoundation.org/';
// $baseurl1='https://www.umeedeinfoundation.org/c_panel/welcome/';

$baseurl='https://unitedwebfox.com/amjad/c_panel/';
$homeurl='https://unitedwebfox.com/amjad/';
$baseurl1='https://unitedwebfox.com/amjad/c_panel/welcome/';

$user_id = $_SESSION['user_id']; 
$login_key = $_SESSION['login_key'];

/*if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    if($_SESSION['type'] ==0){
         $updateData = $db_handle->runQuery("UPDATE `user_login` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==1){
        $updateData = $db_handle->runQuery("UPDATE `master` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==2){
        $updateData = $db_handle->runQuery("UPDATE `employee` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }
    session_unset();
    session_destroy(); 
    print '<script> window.location.replace("'.$baseurl.'"); </script>';
}*/
$_SESSION['LAST_ACTIVITY'] = time();

/*if(!isset($_SESSION['user_id']) || trim($_SESSION['user_id'])=='' || !isset($_SESSION['login_key']) || trim($_SESSION['login_key'])=='') 
{
    if($_SESSION['type'] ==0){
         $updateData = $db_handle->runQuery("UPDATE `user_login` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==1){
        $updateData = $db_handle->runQuery("UPDATE `master` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==2){
        $updateData = $db_handle->runQuery("UPDATE `employee` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }
    session_unset();
    session_destroy(); 
    print '<script> window.location.replace("'.$baseurl.'"); </script>';
}*/
/*if($_SESSION['type'] ==0){
     $userData = $getData->runQuery("SELECT * FROM `user_login` WHERE user_id='". $user_id ."' AND `login_key`='".$login_key."' limit 1");
}elseif($_SESSION['type'] ==1){
    $userData = $getData->runQuery("SELECT * FROM `master` WHERE user_id='". $user_id ."' AND `login_key`='".$login_key."' limit 1");
}elseif($_SESSION['type'] ==2){
    $userData = $db_handle->runQuery("SELECT * FROM `employee` WHERE user_id='". $user_id ."' AND `login_key`='".$login_key."' limit 1");
}*/

$cpassword=$userData[0]['user_pw'];
$access=$userData[0]['access'];
$user_verify=md5($user_id).$userData[0]['login_key'];
/*if($login_key!==$userData[0]['login_key'] || $userData[0]['login_key']=='' || $user_verify!==$_SESSION['user_verify']) 
 {
     if($_SESSION['type'] ==0){
         $updateData = $db_handle->runQuery("UPDATE `user_login` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==1){
        $updateData = $db_handle->runQuery("UPDATE `master` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }elseif($_SESSION['type'] ==2){
        $updateData = $db_handle->runQuery("UPDATE `employee` SET `login_key`='' where `user_id`='".$user_id."' limit 1");
    }
     session_unset();
     session_destroy();
     print '<script> window.location.replace("'.$baseurl.'"); </script>';
 }*/
 function cleanData($string) {
   return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string);
}
?>

 