为什么我的 PHP 会话的变量不再工作?



我有一个用PHP编写的web平台。在这个平台上,我们有一个登录和一个支付页面,它们一直运行良好,但现在PHP会话的变量不再工作了。代码库是一样的。/tmp文件夹存在,我有写入权限,会话正确启动,但每次我设置会话变量并切换到下一页时,超全局数组都是空的。

这是登录脚本。注意第49行

<?php 
include_once('database.php');
include_once('const.php');
include_once('functions.php');
if( isset($_POST['email']) && isset($_POST['password']) ){
$email = htmlspecialchars(strip_tags($_POST['email']));
$password = htmlspecialchars(strip_tags($_POST['password']));
$db = new Database();
$conn = $db->getConnection();
if( accountAlreadyExists($email, "ANAGRAFICA_SOCI") ){
$query = "SELECT * FROM `wcksdc5_DWH`.ANAGRAFICA_SOCI WHERE EMAIL = :email ;";
$stmt = $conn->prepare($query);
$stmt->bindValue(":email", $email, PDO::PARAM_STR);
try{
$stmt->execute();
}catch(PDOException $e){
echo ' Error: ' . $e->getMessage();   
echo ' Line: ' . $e->getLine();   
echo ' File: ' . $e->getFile();
}
if($stmt->rowCount() > 0){
$res = $stmt->fetch(PDO::FETCH_ASSOC);
$dbPass = $res['PASSWORD'];
if(password_verify($password, $dbPass)){
if(!session_start()){
die('Impossibile creare sessione..');
}
$_SESSION['userLogged'] = true;
$_SESSION['nome'] = $res['NOME'];
$_SESSION['email'] = $email;
header('Location: ../dashboard.php');
}else{
die('Password errata, riprovare.');
}
}else{
die("Errore, se il problema persiste contattare l'amministratore di sistema..");
}
}else if( accountAlreadyExists($email, "UTENTI_DA_APPROVARE") ){
$var = checkTmpPaymentStatus($email);
if( $var ){
echo "L'account è in attesa di approvazione da parte del maestro. Si prega di riprovare più tardi";
}else if( !$var ){
if(!session_start()){
die('Impossibile creare sessione di pagamento..');
}
$_SESSION['userLogged'] = true;
$_SESSION['email'] = $email;
header('Location: ../membership-fee.php');
exit();
}else{
"Trovato valore non conosciuto";
}
}else{
die("L'account non esiste. Si prega di ricontrollare le credenziali");
}

}else{
die("Non sono presenti tutti i dati richiesti per performare l'operazione");
}
?>

这是的下一页

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include_once('./php/database.php');
include_once('./php/const.php');
include_once('./php/functions.php');
include_once('./php/json-fn.php');
if(!isset($_SESSION['userLogged']) || $_SESSION['userLogged'] != true){
die("Non possiedi i privilegi per visitare questa sezione");
}
?>

与我编码的内容类似,您必须将其包含在所有页面中

<?php
session_start();
$title=$_SESSION['username'];
$pic=$_SESSION['pic'];
if(!risset($_SESSION['username']))
header('Location:index.php');
?>

您可以在此之后立即启动html代码

要创建会话,您可以使用下面的代码

$_SESSION['username'] = $row['username'];
$_SESSION['pic']=$row['propic'];

销毁会话(注销(

<?php
session_start();
session_destroy();
header('Location:index.php');
?>

最新更新