I have 2 php files. The first, index.php, is where I create the SESSION. It then calls the next file, login.php. I test for the existence of the SESSION in login.php and it says there is no SESSION. I am doing this through XAMPP on my local system and I can see that the SESSION file was created, but login.php can’t detect it. The following code from the two files are both at the top of the file, before any other PHP or HTML code. What am I doing wrong?
I first tried just creating the SESSION. When that didn’t work I set a SESSION value, but still no luck.
index.php
<?php
// Start a session to hold the password
if(!isset($_SESSION)){
ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
session_start();
$_SESSION['pwd']='';
header("LOCATION: login.php");
}
login.php
<?php
if(isset($_SESSION['pwd'])){
if(isset($_POST['submit'])){
// echo "hello";
$global_pwd=$_POST['pwd'];
$_SESSION['pwd']=$global_pwd;
echo $global_pwd;
header("LOCATION: ./index.php");
exit;
}
}else{
echo "no session set";
}
?>