So here is the code for eppkm.php (the page that I need to be protected) The session is settled simply by submit a form that have token value.
<?php session_start();
include_once"pengaturan/crud.php";
if (isset($_POST['token']))
{
$token = $_POST['token'];
$_SESSION['user'] = true;
$konek->login($token);
}
else
{
$_SESSION['user'] = true;
$konek->login($token);
}
?>
And here is the pengaturan/crud.php file, login function:
public function login($token)
{
if (isset($token))
{
$query = "SELECT * FROM master_users WHERE remember_token = '". $token ."'" ;
$hasil = pg_query(Parent::get_dbcon(),$query);
if (pg_num_rows($hasil) != 1)
{
echo "nothing";
//header("Location: http://192.168.0.190/eppkm_ex/public/master/login");
}
}
else{
if(!isset($_SESSION['user'])){
session_destroy();
header("Location: http://192.168.0.190/eppkm_ex/public/master/login");
}
}
}
When I tried to echo the session, it says Undefined index: user
and also tried var_dump the session, the result comes to null which mean the session isn't settled.
Can you help me fix the session? And point me where am I doing wrong :(