Salve
Come mai, secondo voi, questo script di login carica la pagina index.php invece che la pagina loggedin.php?
Grazie!
<?php
if (isset($_POST['submitted'])) {
function absolute_url ($page = 'index.php') {
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
$url = rtrim($url, '/\\');
$url .= '/' . $page;
return $url;
}
function check_login($dbc, $email = '', $pass = '') {
$errors = array();
if (empty($email)) {
$errors[] = 'Hai dimenticato di scriver la tua email.';
} else {
$e = mysqli_real_escape_string($dbc, trim($email));
}
if (empty($pass)) {
$errors[] = 'Hai dimenticato di scrivere la tua password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($pass));
}
if (empty($errors)) {
$q = "SELECT user_id, first_name FROM users WHERE email='$e' AND pass=SHA1('$p')";
$r = @mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) {
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
return array(true, $row);
} else {
$errors[] = 'La tua email o la tua password non sono giuste.';
}
}
return array(false, $errors);
}
require_once ('../mysqli_connect.php');
list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']);
if ($check) {
setcookie ('user_id', $data['user_id'],
time()+3600, '/', '', 0, 0);
setcookie ('first_name', $data['first_name'],
time()+3600, '/', '', 0, 0);
$url = absolute_url ('loggedin.php');
header("Location: $url");
exit();
} else {
$errors = $data;
}
mysqli_close($dbc);
}
if (!empty($errors)) {
echo '<h1>Error!</h1>
<p class="error">Sono avvenuti i seguenti errori:
';
foreach ($errors as $msg) {
echo " - $msg
\n";
}
echo '</p>
Prego riprova.</p>';
}
?>
<h1>Login</h1>
<form action="login1.php" method="post">
Email Address: <input type="text" name="email" size="20" maxlength="80" /> </p>
Password: <input type="password" name="pass" size="20" maxlength="20" /></p>
<input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>