Voting

: max(zero, four)?
(Example: nine)

The Note You're Voting On

patrick dot moire at socopa dot fr
4 years ago
Samples Login / Logout script

login.php :

<?php

// Initisalition
if ($_COOKIE["SESSION"]=='') {
setcookie("SESSION", 'AUTH', 0,'/');

// Identification perdu (time-out ou logoff)
} else if ($_SERVER['PHP_AUTH_USER']!='' && $_COOKIE["USER_SESSION"]=='') {
$_SERVER['PHP_AUTH_USER'] = '';
}

// Controle identification à la base
$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,'/'); // 5 Minutes !

// Mot de passe incorecte : demande identification
} 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');
?>

<< Back to user notes page

To Top