<?php
	
	session_start();   

	include "database.php";
	DB_connexion(); 	
	 
	$var_login = $_GET['login'];
	$var_password = $_GET['pass'];
	
	if($_SESSION['logged'] == "ok")
	{ 	echo "4";
	}
	
	else {

			$sql="SELECT * FROM membres WHERE login = '".$var_login."'";

			//$sql = "SELECT * FROM membres WHERE login ='".$_GET["login"]."'";
	
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);
	
			if($count==1)
			{
				$data = mysql_fetch_assoc($result);
				//$row = mysql_fetch_array($result);   
	
				if($data['password'] != $var_password) 
				{
					echo "2";
					//echo '<p>Mauvais password. Merci de recommencer</p>';
					//exit;
				}
				else { 	
			
						if($data['statut_compte'] == "creation") 
						  {  //echo '<p>Votre compte n'est pas actif</p>';
							echo "3";	
						}
			
						else {
								
								$_SESSION['logged'] = "ok";
								$_SESSION['login'] = $data["login"];
								$_SESSION['user_id'] = $data["id"];
								
								$path = "Users/" .$_SESSION['login'];
								$_SESSION['repertoire']= $path;
								
								/*$file = 'exemple.txt';
								$text = $_SESSION['page_active']; 
								$handle = fopen($file,"w"); 
								fwrite($handle, $text);
								fclose($handle); */
								$tmp = $_SESSION['page_active'];
								$tab = explode(".", $tmp);
								$page = $tmp;
								echo '5*' .$page;
								//echo '5-' .'contact.php';	
								echo "5"; 
								
								
								/*json_encode(array(
								'Variable1' => 'Valeur',
								'Variable2' => 'Valeur'
								));*/
								
								// $expiration =  empty($_POST["CB_Connexion_Automatique"]) ? 0 : time() + 90 * 24 * 60 * 60;
                                   
                                   // Création des cookies
                                //   setcookie("ID_UTILISATEUR", $row["ID_Utilisateur"], $expiration, "/");
                                //   setcookie("NOM_UTILISATEUR", $row["Nom_Utilisateur"], $expiration, "/");
								//setcookie('nom_cookie', $pseudo . '#' . $password, ( time() + 86400 * 90 ));
								// connexion
								//$_SESSION['logged']= "OK";
								//header('Location: compte.php');
								
								
								//$sql = "UPDATE user_online SET connexion = 'online' WHERE login = '".$var_login."' ";
	
						}

					}
			}
			
			
			else {
					echo "1";
					//echo '<p>Mauvais login. Ne fait pas partie de membres?</p>';
				 }
	
	}

	

?>