Devi usare le sessioni!
Codice PHP:
<?php
session_start();
if(isset($_POST['login'])){
$ID = $_POST['id'];
$PASSWORD = $_POST['password'];
$ID_REG = array ("marco", "paolo", "luca", "franco");
$PASS = array("a", "b", "c", "d");
$num_utenti = 4;
for($i=0;$i<$num_utenti;$i++){
if ( ($ID==$ID_REG[$i]) AND ($PASSWORD==$PASS[$i]) ) {
echo "Esatto!";
$_SESSION['logged'] = true;
break;
}
else if($i == ($num_utenti -1)) {
echo "Errato!";
$_SESSION['logged'] = false;
}
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="id" value="">
<input type="password" name ="password" value="">
<input type="submit" value="logini" name="login">
</form>
In un'altra pagina .php:
Codice PHP:
<?php
session_start();
if(isset($_SESSION['logged']) && $_SESSION['logged'] === true) {
header('Location: login_ok.php');
} else {
header('Location: login_ko.php');
}
?>