Ciao ragazzi sto cercando di fare la parte di login utente del sito solo che non riesco a far mantenere il fatto che l'utente si sia loggato anche se navigo nel sito.
Es.: quando mi loggo e clicco sulla pagina index (sarebbe il logo) mi ritorna di nuovo la form di login... ho messo la sessione a tutte le parti... è inserito il form nella condizione di utente non loggato. Ho fatto un esempio che potete verere qui :
myscript72.altervista.org/test/index.php
username: demologin
password: demologin
posto il codice delle pagine
index.php
Codice PHP:
<?php
//Start session
session_start();
?>
<!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" xml:lang="en-US" lang="en-US">
<head>
<title> New Document </title>
</head>
<body>
<table width="800" height="600" border="1">
<tr>
<td height="100"><? include ('header.php') ?></td>
</tr>
<tr>
<td><? include ('body.php') ?></td>
</tr>
<tr>
<td height="60"><? include ('footer.php') ?></td>
</tr>
</table>
</body>
</html>
header.php
Codice PHP:
<?php
//Start session
session_start();
?>
<table border="1" height="90">
<tr>
<td width="200" valign="top">[url="index.php"]index.php[/url]</td>
<td width="400"></td>
<td width="200" valign="top"><? include ('login.php')?></td>
</tr>
</table>
login.php
Codice PHP:
<?php
//Start session
session_start();
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_SELF ?>">
[b]Login utente[/b]
Username:<input type="text" name="username" />
Password:<input type="text" name="password" />
<input type="submit" />
</form>
<?
}
}
?>