I have a problem setting up a session.
Every time i commit log in to the site the session should be created, but it isn't so and i am redirected to notvalid.php
.
The session is created only the second time i try to log in
session_start();
is the first line at every page at my website.
This are the connection functions:
public static function Login($name, $pass)
{
if (!empty($name) && !empty($pass))
{
global $dbh;
$result = $dbh->query("SELECT * FROM users WHERE username = '" . $name . "' AND password = '" . $pass . "'");
$row = $result->fetch(PDO::FETCH_ASSOC);
if ($row > 0)
{
$userid = $row['userid'];
$_SESSION['userid'] = $userid;
$_SESSION['login'] = 'true';
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=userindex.php">';
}
else
{
echo "incorrect username or password.";
$_SESSION['login'] = 'false';
}
}
}
this function check if the session exist:
public static function checklogin()
{
if ($_SESSION['login'] == 'true')
{
return $_SESSION['userid'];
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=notvalid.php">';
}
}
I have tried to enter the site with or without www, i have tried to do as they suggest here
PHP login session wont work on first page load in a NEW window with no cache
But nothing helped.
Any help would be graet.