<?php
ob_start();
session_start();
if (!isset($_SESSION['p']) || md5($_SESSION['p']) != $_GET['p']) {
$_SESSION=array();
$utente=array();//in modo che sia login_3.php a gestire tutti i passaggi
header('location: index.php');
exit();
}
echo "<head><title>{$_SESSION['p']}</title></head>";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = addslashes($_POST['user']);
$password = sha1(addslashes($_POST['pass']));
require_once "utenti.php";
$flag=0;
foreach($utente as $chiave => $valore){
if($chiave == $username && $password == $valore){$flag=1;}
}
if ($flag === 1) {
$_SESSION['p'] = sha1(uniqid(mt_rand()));
$_SESSION['user'] = $username;
header("Location: private.php?r={$_SESSION['p']}");
exit();
}else{//forse meglio metter un else
//$_SESSION=array();
//$utente=array();
header('Location: login_3.php');//in modo che sia login_3.php a gestire tutti i passaggi
exit();
}
}//qui non hai chiuso php per passare all'html
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
text-align: center
color: #000000;
}
.oneColLiqCtr #container {
width: 80%;
background: #FFFFFF;
margin: 0 auto;
border: 0px solid #000000;
text-align: left;
}
.oneColLiqCtr #mainContent {
padding: 150px 20px;
color: #FFF;
}
<!-- metti un po di css anche per il link esci, non è molto bello visualizzato in quella maniera-->
</style>
</head>
<body class="oneColLiqCtr">
<div id="mainContent">
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000">
<tr>
<td width="16%">username</td>
<td width="84%"><input name="user" type="text" id="user"></td>
</tr>
<tr>
<td>password</td>
<td><input name="pass" type="password" id="pass"></td>
</tr>
<tr>
<td> </td>
<td><input name="log" type="submit" id="log" value="log"></td>
</tr>
</table>
</form>
<p><a href="login_3.php">esci</a></p>
</div>
</body>
</html>
<?php
ob_end_flush();//qui manca la chiusura del fllusso
?>