<?php

	session_start();
	
	include('../config_inc.php'); 
	
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "boutique";

	 }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
    	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	 }
	
	

        if(isset($_POST) && isset($_POST['pass']) && isset($_POST['login']) )                                               
          {                                                                       
       				if( !empty($_POST['pass']) && !empty($_POST['login']) )
         			  {
  					    extract($_POST);
				  	    $connexion = mysql_connect($db_host,$db_user,$db_pass); 	
				    	    
				    	    if(!$connexion)
        	  			      { die('Could not connect: ' . mysql_error());
			            	      }
  
			        	    mysql_select_db($db_name, $connexion);
  			  		    $sql = "select * from clients where identifiant='".$login."'";
					    $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
			                    $data = mysql_fetch_assoc($req);
					    
					    if($data['password'] != $pass) 
					      { echo '<p>Mauvais login / password. Merci de recommencer</p>';
					        exit;
					      }
        
                         		    if($data['password'] == $pass) 
					      {
  				    			$_SESSION['email'] = $data["email"];
							$_SESSION['identifiant'] = $data["identifiant"];
					   		$_SESSION['password'] = $data["password"];
				    			$_SESSION['prenom'] = $data["prenom"];
							$_SESSION['id'] = $data["id"];
							$_SESSION['utilisateur_login']= "valide";
			
							if($_SESSION['validation_commande']=="ok")
					  	  	  { header('Location: ../commande/choix_adresse.php');
					  	          }
							if($_SESSION['redirection']== "pilou")
							  {  $_SESSION['redirection']= "aucun";
			    				     header('Location: ../panier/archiver_panier.php');
			   				  }
			    				
			    				if($_SESSION['validation_commande']!="ok" )
					                  { //echo 'Vous etes bien logué';
       			                                    header('Location: compte.php');
       			                                  }  
       			                                  
       			                                //header("location:".$_SERVER['HTTP_REFERER']);  
			                    }
				
				 }			    				
    			                
   	 	                      
		   	    else {  echo 'Il manque quelque chose ?.'; }                                                 
                                                                           
		}                                   




			

?>