<?

$cookie_name = 'ec';
$cookie_time = (3600 * 24 * 30); // 30 days

if(!session_id()) session_start(); 
if(isset($_SESSION['eclesia'])){
	if(is_numeric($_SESSION['eclesia']['idu']))
		$isLogin = 1;
}else if (isset($_COOKIE[$cookie_name]) && !empty($_COOKIE[$cookie_name])){
	
		
	
		//parse_str($_COOKIE[$cookie_name]);
		$text=$_COOKIE[$cookie_name];
		
		//print $_COOKIE[$cookie_name] ;
		//print "<br>$text";
		
		$data_hoje=date("Y-m-d");
		
       $sql="select * from utilizador where md5(email)='$text' and data_inicio <='$data_hoje' and data_fim >='$data_hoje' and estado=1";
	   
	   //print $sql;	

       $result=mysql_query($sql);

	   if(($result) && (mysql_num_rows($result) == 1)) {
			$tauth=mysql_fetch_array($result);
			$_SESSION["eclesia"]['idu']=$tauth['id'];
			$_SESSION["eclesia"]['nome']=$tauth['nome'];
			$_SESSION["eclesia"]['email']=$tauth['email'];
			
			
			setcookie($cookie_name, md5($tauth['email']), time() + $cookie_time, '/');
			
		}
		
		$isLogin = 1;
}else
	$isLogin = 1;
	//$isLogin = 0;