【问题标题】:AS i am using php version 8.0.3 . is these statements are defined in this version因为我使用的是 php 版本 8.0.3 。这些语句是在这个版本中定义的吗
【发布时间】:2021-10-20 04:56:37
【问题描述】:

我如何解决这个问题需要指导。

致命错误:未捕获的类型错误: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} throw in D:\xampp\htdocs\ford\logoff.php on第 9 行

<?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"); 
 }

?>

【问题讨论】:

  • php.net/function.setcookie——你缺少作为第二个参数的值,直接跳到过期,路径成为第三个参数而不是第四个..

标签: php session cookies runtime-error version


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 2019-02-08
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 2015-12-05
    相关资源
    最近更新 更多