首页 > 解决方案 > 因为我使用的是 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"); 
 }

?>

标签: phpsessioncookiesruntime-errorversion

解决方案


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();

推荐阅读