Sto creando un'area riservata, la sto facendo guardando da un libro acquistato, solo che avendola copiata non mi funziona mi rimanda sempre alla pagina del login!! Io penso che sia sbagliato nel libro, ho ricritto tre volte il codice, ma non va? Sapreste indicarmi dove si trova l'errore?
Codice: Pagina template.php
Codice PHP:
<?php
include "auth.inc.php";
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySql</title>
</head>
<body>
<h1>This is the template page</h1>
</body>
</html>
Codice: Pagina auth.inc.php
Codice PHP:
<?php
session_start();
if (isset($_SESSION['logged']) && $_SESSION['loggeg'] == 1) {
// non fa nulla
} else {
$redirect = $_SERVER['PHP_SELF'];
header("Refresh: 5; URL=login.php?redirect=$redirect");
echo "You are being redirected to the login page!
";
echo "(If your browser doesn't support this, " .
"<a href=\"login.php?redirect=$redirect\">click here</a>)";
die();
}
?>
Codice: Pagina login.php
Codice PHP:
<?php
session_start();
$_SESSION['logged'] = 0;
if (isset($_POST['submit'])) {
if ($_POST['username'] == "Admin" &&
$_POST['password'] == "admin") {
$_SESSION['logged'] = 1;
header ("Refresh: 5; URL=" . $_POST['redirect'] . "");
echo "You are being redirected to your original page request!
";
echo "(If your browser doesn't support this, " .
"<a href=\"" . $_POST['redirect'] . "\">click here</a>)";
} else {
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<body>
Invalid Username and/or Password
<form action="login.php" method="post">
<input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login">
</form>
</p>
</body>
</html>
<?php
}
} else {
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<body>
You must be logged in to view this page
<?php
if (isset($_GET['redirect'])) {
$redirect = $_GET['redirect'];
} else {
$redirect = "index.php";
}
?>
<form action="login.php" method="post">
<input type="hidden" name="redirect" value="<?php echo $_GET['redirect']; ?>">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login">
</form>
</p>
<?php
}
?>
</body>
</html>
Grazie Michel