PHP 会话计时器被忽略
PHP session timer is ignored
这是我用于登录功能的脚本。但是如果我想在会话中添加一个计时器,它会忽略它。我试过 10 秒或 1 分钟。但这似乎不起作用。有人知道出了什么问题吗?
这是我用于计时器的代码行:session_set_cookie_params(3600,"/");
感谢正手。
public function login($username, $password) {
$salt="";
$this->user_id=0;
$this->status=0;
$salt_query=$this->mysqli->query(
<<<EOT
SELECT salt
FROM xxxxx
WHERE username="{$username}"
EOT
);
$salt_query = $salt_query->fetch_row();
$salt = $salt_query[0];
$hash = hash('sha512', $password.= $salt);
$result = $this->mysqli->query(
<<<EOT
SELECT werknemer_id,status
FROM xxxxx
WHERE username="{$username}" AND password="{$hash}"
EOT
);
$rij =$result->fetch_row();
if ((empty($rij)) || (empty($rij[0]))) return(1);// Invalid combination
if (($rij[1]<1) || ($rij[1]>2)){
return(2); // Inactive account
}
$this->user_id=intval($rij[0]);
$this->status=intval($rij[1]);
session_regenerate_id();
$_SESSION['werknemer_id']=$this->user_id;
session_set_cookie_params(3600,"/");
return(0); // login
}
来自手册。我没用过它,但它确实说你必须在每个脚本中使用它。另外,你必须在 start_session 之前完成。我认为其中一个是你的问题。
Set cookie parameters defined in the php.ini
file. The effect of this function only lasts for the duration of the script. Thus, you need to call session_set_cookie_params()
for every request and before session_start()
is called.
这是我用于登录功能的脚本。但是如果我想在会话中添加一个计时器,它会忽略它。我试过 10 秒或 1 分钟。但这似乎不起作用。有人知道出了什么问题吗?
这是我用于计时器的代码行:session_set_cookie_params(3600,"/");
感谢正手。
public function login($username, $password) {
$salt="";
$this->user_id=0;
$this->status=0;
$salt_query=$this->mysqli->query(
<<<EOT
SELECT salt
FROM xxxxx
WHERE username="{$username}"
EOT
);
$salt_query = $salt_query->fetch_row();
$salt = $salt_query[0];
$hash = hash('sha512', $password.= $salt);
$result = $this->mysqli->query(
<<<EOT
SELECT werknemer_id,status
FROM xxxxx
WHERE username="{$username}" AND password="{$hash}"
EOT
);
$rij =$result->fetch_row();
if ((empty($rij)) || (empty($rij[0]))) return(1);// Invalid combination
if (($rij[1]<1) || ($rij[1]>2)){
return(2); // Inactive account
}
$this->user_id=intval($rij[0]);
$this->status=intval($rij[1]);
session_regenerate_id();
$_SESSION['werknemer_id']=$this->user_id;
session_set_cookie_params(3600,"/");
return(0); // login
}
来自手册。我没用过它,但它确实说你必须在每个脚本中使用它。另外,你必须在 start_session 之前完成。我认为其中一个是你的问题。
Set cookie parameters defined in the
php.ini
file. The effect of this function only lasts for the duration of the script. Thus, you need to callsession_set_cookie_params()
for every request and beforesession_start()
is called.