Schema autenticazione

Codice PHP:



<?php
if(isset($_GET['error']) and $_GET['error']==1)
 echo 
"Errore: nome utente o password non valide!";
 
//Oppure fai l'include di un file di errore
?>

<form method="post" action="authenticate.php">
<input type="text" name="login" />
<input type="password" name="pwd" />
<input type="submit" name="submit" value="entra!" />
</form>
Codice PHP:
<?php
//File: authenticate.php


session_start();
$login=trim($_POST['login']);
$pwd=trim($_POST['pwd']);

include(
"utenti.php");

if(isset(
$utente[$login]) and $utente[$login]==$pwd){
 
//loggato con successo
 
$_SESSION['ok']=1;
 
header("Location: PAGINA_CHE_VUOI");
 exit;
}
else{
 
//non loggato
 
header("Location: login.php?error=1");
 exit;
}

?>
Codice PHP:
<?php
//utente.php
$utente['admin']="admin";
//eventualmente altri utenti...
?>
Codice PHP:
<?php
//Pagina protetta: deve iniziare con questo codice
session_start();
if(isset(
$_SESSION['ok']) and $_SESSION['ok']==1){
 
//L'utente è già loggato
?>

<?php
}
else{
 
//L'utente non è loggato, lo mando alla pagina di login
 
header("Location: login.php");
 exit;
}
?>
Il succo è questo, poi puoi adattare come vuoi!