douyi6922 2015-12-12 17:07
浏览 137

升级到PHP 5.6后,PHP会话将无法运行

Recently my hosting provider decided to upgrade from PHP version 5.4 tot version 5.6, and after that I experience a problem with sessions I'm using in my login system.

The login system is a simple one, after checking user name and password a session variable is set and the user is redirected to the protected page. Once there, it will be checked if the mentioned session variable is set or not to decide if the page has to be shown or if the user has to be redirected to the login page.

As suggested, up to a few days ago everything was working fine! However, when a user tries to log in now and is redirected to the protected page, he will be sent back to the login page, probably because of a problem with the session due to the PHP upgrade.

Below are some parts of the code.

<?php
//login page
session_start();
if ($check >= 1)
// If combination user name password is correct.
{
  session_regenerate_id(TRUE);
  $_SESSION['logged_in'] = TRUE;
  header('Location: /');
  exit();
}
?>

and

<?php
// protected page
session_start();
if (!isset($_SESSION['logged_in']))
// User not logged in.
{
  session_unset();
  if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
      $params["path"], $params["domain"],
      $params["secure"], $params["httponly"]
    );
  }
  session_destroy();
  header('Location: /login');
}
else
// Logged in, show page.
{
  // page
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 matlab求解平差
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办