简体   繁体   English

PHP集中的SESSION变量,但无法检索值

[英]SESSION variable in php set but can't retrieve values

I've started a session in a php file and also the session variable is been assigned with the result of the query successfully, I've even tried displying it in the same page it works perfectly fine.. but when I try accessing that particular session variable in a other page is shows it's not set.. 我已经在php文件中开始了一个会话,并且会话变量也已成功分配了查询结果,我什至尝试将其显示在同一页面中也可以正常工作..但是当我尝试访问该特定对象时另一页中的会话变量显示未设置。

here are the code snippet: page1.php 这是代码段:page1.php

$email=$_POST['email'];
$password=$_POST['password'];
$query="Select * from sign_up where email='$email'";
$resultObj=$connection->query($query);
$row=$resultObj->fetch_assoc();
//print_r($row);


if(strcmp($password,$row['pass'])==0){
session_start();   
$_SESSION['signin']=$row;

if(isset($_SESSION['signin'])){
    echo "Assigned\n";
    print_r($_SESSION['signin']);
}

Page2.php 使page2.php

<?php

session_start();
if(isset($_SESSION['signin'])){
    print_r($_SESSION['signin']);
}else{
    echo "Not Set..";
}

?>

It shows not set in page2.php even though it's set in page1.. 即使已在page1中设置,它也显示未在page2.php中设置。

Note:both page1.php and page2.php are in different folders, I assume that ain't a big deal. 注意:page1.php和page2.php都位于不同的文件夹中,我认为这没什么大不了的。

Mind shifting the session_start() to the top of the page in page1.php , assuming that ain't a big deal. 假设这没什么大不了 ,请注意session_start()移到page1.php中页面的顶部 That should help. 那应该有帮助。

<?php
session_start(); 
....

Otherwise I'd suggest you to have a look here - unable to get $_SESSION variable 否则,我建议您在这里看看- 无法获得$ _SESSION变量

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM