私はこのスクリプトを書きました。動作していますが、ページを離れたり、ページに戻ったりすると、セッションが保存されません。私が間違っていることは何ですか?
login.php
<?php
session_start();
require 'classes.php';
//if user is not yet authorized
if ($_SESSION['user']->iduser == null) {
$dbhandle = mysql_connect($hst, $usr, $pass);
if (!$dbhandle) {
die('Could not connect: ' . mysql_error());
}
$selected = mysql_select_db($dbName, $dbhandle)
or die("Could not select the database");
$result = mysql_query(" query ");
$resultArray = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result); //count how many rows returned
//if 0 rows returned, then login was failed
if ($num_rows == 0) {
die('Error! Access denied. Incorrect username or password.');
} else { //if username and password match
$_SESSION['user'] = new user();
$_SESSION['user']->iduser = $resultArray{'iduser'};
$_SESSION['user']->fname = $resultArray{'fname'};
echo 'Dear ' . $_SESSION['user']->fname . ', you succesfully logged in!';
}
//if user is already logged in
} else {
echo 'You already logged in!<br>Your email is: ';
}
?>
クラスユーザー
<?php
class user {
public $iduser = null;
public $fname = null;
public $lname = null;
public $email = null;
public $password = null;
public $permission = null;
}
?>