简体   繁体   中英

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..

here are the code snippet: 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

<?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..

Note:both page1.php and page2.php are in different folders, I assume that ain't a big deal.

Mind shifting the session_start() to the top of the page in page1.php , assuming that ain't a big deal. That should help.

<?php
session_start(); 
....

Otherwise I'd suggest you to have a look here - unable to get $_SESSION variable

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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