php - 因为我使用的是 php 版本 8.0.3 。这些语句是在这个版本中定义的吗
问题描述
我如何解决这个问题需要指导。
致命错误:未捕获的类型错误:setcookie():参数 #3 ($expires_or_options) 必须是数组 | int 类型,字符串在 D:\xampp\htdocs\ford\logoff.php:9 堆栈跟踪:#0 D:\ xampp\htdocs\ford\logoff.php(9): setcookie('PHPSESSID', '1629284838', '/') #1 {main} 在第 9 行的 D:\xampp\htdocs\ford\logoff.php 中抛出
<?php
session_start();
if(isset($_SESSION["logged_in"])){
$_SESSEION =[];
if(ini_get('session.use_cookies')){
setcookie(session_name(),time()-15,"/");
}
session_destroy();
header("Location:login.php");
}
else{
header("Location:login.php");
}
?>
解决方案
从session_destroy手册页:
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();
推荐阅读
- python - bytearray() 的 append() 方法不允许我附加从 32 到 126 的任何数字。什么给出?
- python - 发生异常:TypeError 'float' 对象不可下标
- java - 为什么 java swing 计时器类不起作用?
- laravel - 如何使我的表始终位于最后一行
- javascript - 将状态对象从 React 组件函数传递给外部函数
- php - 谷歌云端硬盘垃圾清除使用 PHP 不起作用
- java - 在数组中找到回文数的个位数和
- elasticsearch - 如何根据主机将 StormCrawler 内容发送到多个 Elasticsearch 索引?
- r - 如何修复if循环以在R中打印奇数/偶数?
- java - 如何重用一个通用面板?