- <?php
- class auth
- {
- function auth(){}
- function is_auth()
- {
- $fi=fopen('.htpasswd','r');
- $list=fread($fi,filesize('.htpasswd'));
- fclose($fi);
- $t=explode(":",$list);
- if(!isset($_SESSION['connexion']))$_SESSION['connexion']=0;
- if($_SESSION['connexion']==2 && crypt($_SERVER['PHP_AUTH_PW'],"sd")!=$t[1])$_SESSION['connexion']=3;
- if($_SESSION['connexion']==2 || $_SERVER['PHP_AUTH_USER']!=$t[0] || crypt($_SERVER['PHP_AUTH_PW'],"sd")!=$t[1] )
- {header("WWW-Authenticate: Basic realm=\"\"");$this->out();}
- else
- {
- print("<a href=\"".basename($_SERVER['PHP_SELF'])."?end\">Deconnexion</a><br/>");
- $_SESSION['connexion']=1;
- }
- }
- function close()
- {
- $_SESSION['connexion']=2;
- $this->out();
- }
- function out(){die("Non autorisé");}
- };
- $user = new auth;
- if(isset($_GET['end'])){$user->close();}
- $user->is_auth();
- ?>
<?php
class auth
{
function auth(){}
function is_auth()
{
$fi=fopen('.htpasswd','r');
$list=fread($fi,filesize('.htpasswd'));
fclose($fi);
$t=explode(":",$list);
if(!isset($_SESSION['connexion']))$_SESSION['connexion']=0;
if($_SESSION['connexion']==2 && crypt($_SERVER['PHP_AUTH_PW'],"sd")!=$t[1])$_SESSION['connexion']=3;
if($_SESSION['connexion']==2 || $_SERVER['PHP_AUTH_USER']!=$t[0] || crypt($_SERVER['PHP_AUTH_PW'],"sd")!=$t[1] )
{header("WWW-Authenticate: Basic realm=\"\"");$this->out();}
else
{
print("<a href=\"".basename($_SERVER['PHP_SELF'])."?end\">Deconnexion</a><br/>");
$_SESSION['connexion']=1;
}
}
function close()
{
$_SESSION['connexion']=2;
$this->out();
}
function out(){die("Non autorisé");}
};
$user = new auth;
if(isset($_GET['end'])){$user->close();}
$user->is_auth();
?>