So I created a login.php for our Web application project but it doesn't seem to let me login in a session
Here's my login.php code:
<?php
if(isset($_POST['username']) && isset($_POST['pass'])){
include("sql_connect.php");
$res = mysqli_query($mysqli, "SELECT * FROM customer
WHERE idnum='".$_POST['username']."'
AND password = '".$_POST['pass']."'");
if(mysqli_num_rows($res)==1){
$_SESSION['logged_in'] = "$idnum"; //creates and initializes the session with the name 'variable_name'
echo $_SESSION['logged_in']; //will now print out value
header("location:index.php");
}
else{
echo "Incorrect Username/Password!";
}
}
?>
and here's my index.php code:
<?php
session_start();
if(!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] != "TRUE"){
header("location:login.php");
}
include("sql_connect.php");
?>
login.phpis missingsession_start();$_SESSION['logged_in'] != "TRUE"this is always true... $_SESSION['logged_in'] never is equal to text 'TRUE'$_SESSION['logged_in'] != "TRUE"as stated.TRUEand"TRUE"are two different animals; one is a boolean while the other is a string. You don't even need that anyway. Plus, we don't know if your form is ok or not.