【发布时间】:2020-09-07 01:51:05
【问题描述】:
我有一个用 PHP 编写的网络平台。在这个平台上,我们有一个登录页面和一个支付页面,它们以前都可以正常工作,但现在 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");
}
?>
【问题讨论】:
-
尝试将
session_start();放在页面顶部<?php标记之后和任何其他代码或文本之前。以后可以省去很多麻烦。此外,您要访问的所有页面session都应该在顶部
标签: php session session-variables