Is it possible to save session values between pages? I did a little script
to let the users login. I use this script to check username and password the
user introduces in a form in the main page, index.php.
If a user is found with username and password, than I create
$_SESSION['Login'] and assign it a value of true, else I assign it a value
of false. If a user is non registered, I send it to the proper page to
register, RegistraUtente. php, if he is registered yet, I send him back to
index.php
But here in index.php $_SESSION['Login'] has no value.
Here is the script I wrote:
<?php
session_start() ;
include("dbconn ect.php");
$tabella="table ";
$dbname="Zucca" ;
if (!isset($_SESSI ON['Login']))
{
$_SESSION['Login']=false;
}
$IdUser=session _id();
$data=date('Y-m-d');
if (!ISSET($HTTP_C OOKIE_VARS["PiOnLine"]))
setcookie("PiOn Line",$IdUser,t ime()+60*60*24* 365);
else
$IdUser=$HTTP_C OOKIE_VARS["PiOnLine"];
mysql_select_db ($dbname,$db);
$username=$_POS T["username"];
$password=$_POS T["password"];
$query="Select Username, UserPassword from $tabella where
('$password'=Us erPassword) and ('$username'=Us ername)";
$result=mysql_q uery("$query") or die(mysql_error ());
// Se esiste l'utente con username e password allora consenti il login
if (mysql_num_rows ($result)==1)
{
$_SESSION['Login']=true;
session_write_c lose();
$url="index.php ";
header ("Location: $url");
}
else // Invia l'utente sulla pagina di registrazione
{
$_SESSION['Login']=false;
session_write_c lose();
$url="RegistraU tente.php";
header ("Location: $url");
}
?>
Franz
to let the users login. I use this script to check username and password the
user introduces in a form in the main page, index.php.
If a user is found with username and password, than I create
$_SESSION['Login'] and assign it a value of true, else I assign it a value
of false. If a user is non registered, I send it to the proper page to
register, RegistraUtente. php, if he is registered yet, I send him back to
index.php
But here in index.php $_SESSION['Login'] has no value.
Here is the script I wrote:
<?php
session_start() ;
include("dbconn ect.php");
$tabella="table ";
$dbname="Zucca" ;
if (!isset($_SESSI ON['Login']))
{
$_SESSION['Login']=false;
}
$IdUser=session _id();
$data=date('Y-m-d');
if (!ISSET($HTTP_C OOKIE_VARS["PiOnLine"]))
setcookie("PiOn Line",$IdUser,t ime()+60*60*24* 365);
else
$IdUser=$HTTP_C OOKIE_VARS["PiOnLine"];
mysql_select_db ($dbname,$db);
$username=$_POS T["username"];
$password=$_POS T["password"];
$query="Select Username, UserPassword from $tabella where
('$password'=Us erPassword) and ('$username'=Us ername)";
$result=mysql_q uery("$query") or die(mysql_error ());
// Se esiste l'utente con username e password allora consenti il login
if (mysql_num_rows ($result)==1)
{
$_SESSION['Login']=true;
session_write_c lose();
$url="index.php ";
header ("Location: $url");
}
else // Invia l'utente sulla pagina di registrazione
{
$_SESSION['Login']=false;
session_write_c lose();
$url="RegistraU tente.php";
header ("Location: $url");
}
?>
Franz
Comment