salve ho scritto questo semplice codice per poter fare il login con le sessioni, ma non funziona... dopo che premo per fare il login mi manda sempre nella pagina di errore, il problema e' che la variabile di sessione non viene registrata... è sempre vuota... mi sapete dire perche?
pagina login...
<?php
session_start();
$_SESSION['Username'] = "";
if (isset($_POST['user'])){
if(connectToDb()){
$user = trim(htmlentities($_POST['user']));
$pass = trim(htmlentities($_POST['pwd']));
$query = "SELECT * FROM Admin WHERE User='$user' AND Pass='$pass'";
$result = mysql_query($query);
if ($result && mysql_num_rows($result) == 1){
$row = mysql_fetch_row($result);
$_SESSION['Username']=$user;
//$_SESSION['Pass']=$row[1];
print($_SESSION['Username']." ".mysql_num_rows($result));
header('location:verifica.php');
}else{
header('location:login_failed.php');
}
}else{
print('Errore DB');
}
}
?>
<html>
<head>
<title>Esempio login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onLoad="document.form1.user.focus()">
<form name="form1" method="POST" action="verifica.php">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Nome utente: </td>
<td><input name="user" type="text" id="user"></td>
</tr>
<tr>
<td>Password: </td>
<td><input name="pwd" type="password" id="pwd"></td>
</tr>
<tr>
<td colspan="2"><input name="Submit" type="submit" value="Entra"></td>
</tr>
</table>
</form>
</body>
</html>
pagina verifica.php
<?php
// Controllo accesso
session_start();
if ($_SESSION['Username'] == ""){
header('location:login_failed.php');
exit;
}
//codice pagina in caso di effettuato login....
AIUTOOOOOOOOOOOOOOO