I have a login checker that redirects the user to a homepage if the check succeeds. I save the username in session variable at 'username' index.
<?php
ob_start();
include("db.php");
session_start();
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
$result=pg_query($sql);
$count=pg_num_rows($result);
if($count==1){
$_SESSION['username'] = $myusername;
header("location:homepage.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
I try to access the index but get an error that it doesn't exists
<p>WELCOME!</p>
<?php
session_start();
echo $_SESSION['username'];
I call session_start in each file so I can't see the problem.