<?php
	$result = mysql_query($sql_query="SHOW TABLES LIKE 'oxg_users'") or mysql_die();
	if(mysql_num_rows($result) > 0)
	{
		if(isset($_SERVER['PHP_AUTH_PW']))
		{
			$AUTH_PW = md5($_SERVER['PHP_AUTH_PW']);
			$PW="";
			$sql_query = "select pass, nom, prenom, role from oxg_users where nom='".$_SERVER['PHP_AUTH_USER']."' and pass='".$AUTH_PW."'";
			$resultat=mysql_query($sql_query) or mysql_die();
			while($tab = mysql_fetch_array($resultat,MYSQL_ASSOC))
			{
				if(isset($tab['pass']))
				{
					$PW = $tab['pass'];
					$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);
		}
	}
?>