不推荐使用:函数session_is_registered() - 有关如何解决此错误的任何想法

时间:2012-06-11 13:47:44

标签: php session php-5.3 deprecated

  

不推荐使用:函数session_is_registered()已弃用   第37行/home/socia125/public_html/logout.php

     

警告:无法修改标头信息 - 已发送的标头   (输出从/home/socia125/public_html/logout.php:37开始)   第38行/home/socia125/public_html/logout.php

这是我正在使用的代码

<?php

session_start();
// Force script errors and warnings to show on page in case php.ini file is set to not     
display then
error_reporting(E_ALL);
ini_set('display_errors', '1');

// Unset all of the session variables
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie
if (isset($_COOKIE['idCookie'])) {
setcookie("idCookie", '', time()-42000, '/');
setcookie("passCookie", '', time()-42000, '/');
 }
 // Destroy the session variables
 session_destroy();
 // Check to see if their session is in fact destroyed
 if(!session_is_registered('firstname')){ 
 header("location: index.php"); // << makes the script send them to any page we set
 } else {
 print "<h2>Could not log you out, sorry the system encountered an error.</h2>";
  exit();
  } 
  ?> 

1 个答案:

答案 0 :(得分:2)

只需检查会话变量是否已设置:

if(!session_is_registered('firstname')){ 

变为

if (!isset($_SESSION['firstname'])) {