0

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.

Syam Sundar K
  • 129
  • 1
  • 12

1 Answers1

1

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.