ciao ora funziona ma non so perchè perde la variabile che mi serve ($username) passando da una pagina all'altra.
Ho aggiornato l'esempio che potete verere qui :
myscript72.altervista.org/test/index.php
mentre questo è il codice aggiornato.
header.php
login.phpCodice PHP:
<table border="1" height="90">
<tr>
<td width="200" valign="top">[url="index.php"]index.php[/url]
</td>
<td width="400">[url="logout.php"]logout.php[/url]
</td>
<td width="200" valign="top">
<?
//Start session
session_start();
print_r($_SESSION);
if(empty($_SESSION['SESS_MEMBER_ID']) ) {
include ('login.php');
} else {
echo "Ciao $username";
}
?>
</td>
</tr>
</table>
Codice PHP:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
include("db_vars.inc");
//Sanitize the value received from login field
//to prevent SQL Injection
if(!get_magic_quotes_gpc()) {
$username=mysql_real_escape_string($_POST['username']);
}else {
$username=$_POST['username'];
}
//Create query
$qry="SELECT iduser FROM users WHERE username='$username' AND password='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result)>0) {
//Login Successful
$member=mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID']= $member['iduser'];
session_write_close();
echo "ciao $username
";
}else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
[b]Login utente[/b]
Username:<input type="text" name="username" />
Password:<input type="text" name="password" />
<input type="submit" />
</form>
<?
}
}
?>![]()