I've been bothered by this problem for quite a while now, and i just can't figure it out. Once a user tries to login, he's being logged in. But once he loads another page, or refreshes he's logged out right away. The really weird thing is, that once i test it locally on XAMPP it works without a problem, but when it runs on my webpage, it dosen't work. They run on almost the same version of PHP 5.5.11 (locally) 5.5.18 (on webpage) Can anyone explain me what's wrong? Any help is greatly appreciated
From login.php
$query = "SELECT * FROM user WHERE email='$email' AND password='$passi' AND com_code IS NULL";
$result = mysqli_query($mysqli,$query)or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
if( $num_row ==1 )
{
$_SESSION['user_name']=$row['username'];
header("Location: index.php");
}
else
{
$message= "Wrong login message";
}
From my other pages, that checks if the user is logged in:
if($_SESSION['user_name'] == '') {
die ("Please log in to see this page");
} else {
echo "Hey $_SESSION[user_name]!";
}