I was using this code before and it worked but then i updated my code base to php 5.3 and now it doesnt work anymore. I have looked over the logic time and time again and it should work fine, what am i doing wrong, or am i using deprecated functions again? here is my login index.php file
<?php
ini_set('session.save_path', '/opt/lampp/htdocs/tmp'); // linux specific line for setting session tmp path
session_start();
$con = mysqli_connect("localhost", "root", "", "numbers") or die(mysqli_error($con));
$error = NULL;
if(isset($_POST['login']))
{
//get username and password entered by user
$myusername=mysqli_real_escape_string($con,$_POST['username']);
$mypassword=mysqli_real_escape_string($con,$_POST['password']);
$sql="SELECT username, password FROM admin WHERE username='".$myusername."' AND BINARY password='".$mypassword."' UNION SELECT username, password FROM superuser WHERE username='".$myusername."' AND BINARY password='".$mypassword."'";
$check= mysqli_query($con,$sql);
$row = mysqli_fetch_row($check);
if($row[0]!="" && $row[1] !="") //compare username and password to ones found in database
{
## set logged_in to true
$_SESSION['logged_in']= true;
## set username session
$_SESSION['user'] = $row[0];
header('location: table.php');
exit();
}
else
{
$error="Your Login Name or Password is invalid";
//echo "$error";
//echo "<META http-equiv=' refresh' ;URL='index.php'>";
}
}
This part works fine, at least i think it does.
while this little part here is whats giving me the trouble.
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] == false){
header('Location: index.php');
exit();
}
Before i could put that in front of any file i wanted to protect with a password, now it doesnt work anymore, anyone can just copy the url and paste it in and it will take you right to the page without prompting for a password, it should prompt for a password if a session hasnt be started already, and in this case it has not, what exactly is wrong with it?
Thanks all, every bit of guidance is welcomed and appreciated.