我有以下代码:
页面Login.php
flags

和perfil.php(登录后用户被带走)
<?PHP
session_start();
include("conexion.php");
$conn = conexion();
extract($_POST);
$password = md5($pass);
echo $password;
$sql1="Select * from miembro where user='".$user."'and pass ='".$password."'";
$re= mysqli_query($conn,$sql1);
$numrows1 = mysqli_num_rows($re);
echo $sql1;
echo $numrows1;
if ($numrows1==0 or $numrows1>=2){
$_SESSION['session'] = "no";
header('Location:' . getenv('HTTP_REFERER'));
}else{
$row = mysqli_fetch_array($re);
$_SESSION['nombre'] = $row["nombre"];
echo $_SESSION['nombre'];
$_SESSION['codigo'] = $row["codigo"];
$_SESSION['pass'] = $row["pass"];
$_SESSION['apellido'] = $row["apellido"];
$_SESSION['telefono'] = $row["telefono"];
$_SESSION['user'] = $row["user"];
$_SESSION['cargo'] = $row["cargo"];
$_SESSION['correo'] = $row["correo"];
$_SESSION['session'] = "si";
$_SESSION['last_time'] = time();
header("Location: ./actions/perfil.php");
}
?>
&#13;
它没有工作,我不明白为什么。会话开始的时间保存在一个变量中,稍后用if循环进行分析,所以如果时间超过10秒,用户应该被强制退出并再次进入登录页面,但我不能让它起作用。请问有人帮帮我吗?
答案 0 :(得分:0)
嗯,也许尝试以这种方式设置cookie:
setcookie($cookie_name, $cookie_value, time() + 10, "/"); // 86400 is one day
然后检查它是否由isset($ _ COOKIE [$ cookie_name])
设置