So I have the index.php page.
<?php
session_start();
if (!isset($_SESSION['var1'])) {
echo "session not started...";
die();
} else {
echo "session started";
die();
}
?>
It also has a login form that leads to following login script:
<?php
session_start();
include('config.php');
$username=$_POST['username'];
$password=$_POST['password'];
if($_SERVER['REQUEST_METHOD'] == "POST") {
$result = mysql_query("SELECT ..blahblah");
if(mysql_num_rows($result) > 0) {
$_SESSION['var1'] = 1;
}
}
if(!isset($_SESSION['var1'])) {
echo "wrong login or password";
} else {
header("location:http://mysite.com");
}
?>
The thing is that for other pages the variable is set, but not for index.php.
I don’t get it. Don’t see the error anywhere.
Here’s result of print_r($_SESSION):
On other page: Array ( [is_logged_in] => 1 )
On Index page: Array ( )
Maybe you generate your session from the http://www.mysite.com And you redirect to http://mysite.com.
Be careful with session. Web site with www. and without aren’t same for sessions.