I don't get it. I try the code and it works when i log out it doesn't work when i log in again.
test.php
<?php
session_start();
var_dump ($_SESSION['username']);
var_dump ($_SESSION['loggedin']);
function is_logged()
{
if(isset($_SESSION['loggedin']))
{
return true;
}else{
return false;
}
}
if(is_logged())
{
echo "Welcome, ". $_SESSION['username'] ."!";
}else{
echo "Welcome, Guest!";
}
validapass.php
<?php
session_start();
include "db_connect.php";
mysql_select_db($dbname, $connect);
$username = $_POST['username'];
$pass = $_POST['pass'];
$sql="SELECT username, password FROM alunos WHERE username='". $username. "' AND '". $pass ."'";
$resultado = mysql_query($sql, $connect) or die(mysql_error());
if(mysql_affected_rows() == 1)
{
$_SESSION['username'] = $username;
$_SESSION['loggedin'] = 1;
header("Location: test.php");
}else{
header("Location: login_form.php");
}
mysql_close($con);
?>