I'm having trouble with PHP session variables: I try setting the variables, and they can't be read even in the same file, much less another file.
Sorry if the question has been asked before, but I can't find anything that doesn't say "make sure you have session_start()
at the beginning of the file."
Lines 1, 2, & 3 of file:
<?php
ini_set('session.save_path','/home/[username]/session_data'); // Just in case, points to a correct directory
session_start();
Later, after username validation, and login, the variables are set, and code tries to echo
them out:
$_SESSION['login'] == "true";
$_SESSION['username'] == $username;
$_SESSION['password'] == sha1($password);
//header("Location: [admin page hidden]"); // Code would normally redirect to admin page (commented out for debugging), and exit
//exit;
echo "Username: ".$username."<br />"; // The following 4 lines try to print out the data
echo "Password: ".$password."<br />";
echo "Secure Password: ".sha1($password)."<br />";
echo "Session Username: ".$_SESSION['username']."<br />";
The output is:
Username: root
Password: [correct password]
Secure Password: [correct sha1 version of password]
Session Username:
The secure password (sha1
, what is checked) matches what is in the database file, I checked. Nothing comes out for the session variables, even though it was created 7 lines previously. The directory that I pointed the save path to just has a blank file for the session.
Does anyone have any clue why this doesn't work, or advice on how to proceed? Any helpful response is appreciated.