The Note You're Voting On
patrick dot moire at socopa dot fr ¶4 years ago
Samples Login / Logout script
login.php :
<?php
if ($_COOKIE["SESSION"]=='') {
setcookie("SESSION", 'AUTH', 0,'/');
} else if ($_SERVER['PHP_AUTH_USER']!='' && $_COOKIE["USER_SESSION"]=='') {
$_SERVER['PHP_AUTH_USER'] = '';
}
$ident = executeSQL("SELECT * FROM UTILISATEURS WHERE upper(IDENTIFIANT)=Upper('".$_SERVER['PHP_AUTH_USER']."')");
if ($_SERVER['PHP_AUTH_USER']!='' && strtoupper($ident['IDENTIFIANT'])==strtoupper($_SERVER['PHP_AUTH_USER']) && $ident['MOT_DE_PASSE']==$_SERVER['PHP_AUTH_PW']) {
$user = $_SERVER['PHP_AUTH_USER'];
setcookie("USER_SESSION", $user, time()+300,'/'); } else {
setcookie("SESSION", '', 1,'/');
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die;
}
?>
<html>
<body >
Bonjour <?php echo $ident['NOM'].' '.$ident['PRENOM']; ?>
<br>
<br>
<a href="http://logout.php">Deconnexion</a>
</body>
</html>
logout.php :
<?php
setcookie("USER_SESSION", '', 1,'/');
header('Location: http://login.php');
?>