Im attempting to log users into a website using their ID and a hashed password (Checks the database and passes).
However, when i successfully log in, the server is not holding all the $_SESSION Variables i have set.
PHP Login Code:
<?php
session_start();
include '../Main/dbh.php';
$ID=$_POST['ID'];
$pwd=$_POST['Password'];
$spwd=md5($pwd);
$sql = "SELECT * FROM account WHERE ID='$ID' AND pwd='$spwd'";
$result = $conn->query($sql);
if(!$row = $result->fetch_assoc()) {
Header("Location: ../Index.php");
} else {
$_SESSION['LoggedIn'] = 1;
$_SESSION['ID'] = $row['ID'];
$_SESSION['First Name'] = $row['First Name'];
$_SESSION['Last Name'] = $row['Last Name'];
$_SESSION['Email'] = $row['Email'];
$_SESSION['pwd'] = $row['pwd'];
$_SESSION['staff'] = $row['staff'];
$_SESSION["Executive"] = $row['Executive'];
$_SESSION['HR'] = $row['HR'];
header("Location: Login.php");
}
DBH Connection:
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "AVA Screenshot Centre";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else { echo "YA!"; }
?>
Header Code (Echo Function):
<?php
session_start();
include 'SiteURL.php';
echo $_SESSION['ID'];
$UserStaff="0";
?>
The Error comes when i am trying to echo the $_SESSION['ID'] variable, or any other set in the Login process. Sorry, been a while since i have coded, all help is appreciated.