nel file "index.php"
<?php include_once 'access.inc.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Il Network OSI - Opificio Sistemi d'Impresa</title>
</head>
<body>
Sito non protetto</p>
<?php if (loggedIN()): ?>
tu sei attualmente loggato!Logout</p>
<?php endif; ?>
</body>
</html>
nel file "access.inc.php"
<?php
require_once 'config.inc.php';
function loggedIN()
{
return isset($_SESSION['authorized']);
}
//Processa il tentativo di login
if(isset($_POST['login'])){
if($_POST['username'] == ADMIN_USER and
$_POST['password'] == ADMIN_PASS) {
$_SESSION['authorized'] = TRUE;
}
}
// Processa il logout
if(isset($_REQUEST['logout'])){
unset($_SESSION['authorized']);
}
?>
nel file "config.inc.php"
<?php
define('ADMIN_USER', 'root');
define('ADMIN_PASS', 'root');
?>
nel file "admin.php"
<?php require 'secure.inc.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sito Amministrazione Area</title>
</head>
<body>
<h1>Administrative Options</h1>
<ul>[*]HOME[/list]
Logout</p>
</body>
</html>
nel file "secure.inc.php"
<?php
require_once 'access.inc.php';
if (!loggedIN()) {
include 'login.inc.php';
exit;
}
?>
nel file "login.inc.php"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>
<h1>Please log in for access</h1>
<div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>User name:
<input type="text" name="username" /></label>
<label>Password:
<input type="password" name="password" /></label>
<input type="submit" value="Log in" />
</form>
</div>
</body>
</html>
Ho provato ad effettuare il login ma non mi funziona...come mai?? potete correggere per favore?? )