<?php
	$result = mysql_query($sql_query="SHOW TABLES LIKE 'oxg_users'");
	if(mysql_num_rows($result) > 0)
	{
		if(isset($_SERVER['PHP_AUTH_PW']))
		{
			$AUTH_PW = md5($_SERVER['PHP_AUTH_PW']);
			$PW="";
			$sql_query = "select password, nom, prenom, privilege from oxg_users where login='".$_SERVER['PHP_AUTH_USER']."' and password='".$AUTH_PW."'";
			$resultat=mysql_query($sql_query) or mysql_die();
			while($tab = mysql_fetch_array($resultat,MYSQL_ASSOC))
			{
				if(isset($tab['password']))
				{
					$PW = $tab['password'];
					$NOM = $tab['nom'];
					$PRENOM = $tab['prenom'];
				}
			}
			if( $AUTH_PW != $PW )
			{
				header("status: 401 Unauthorized");
				header("HTTP/1.0 401 Unauthorized");
				header('WWW-authenticate: Basic '.'realm="ACCESS SECURISE APPLICATION"');
				print("Vérification : ERREUR"); 
				exit(0);
			}
		}
		else
		{
			header("status: 401 Unauthorized");
			header("HTTP/1.0 401 Unauthorized");
			header('WWW-authenticate: Basic '.'realm="ACCESS SECURISE APPLICATION"');
			echo "Vous devez vous identifier.";
			exit(0);
		}
	}
?>