dongtiao0657 2014-07-09 09:10
浏览 26
已采纳

pHp会话错误?

I've been trying to figure out why my code isn't working on my PC at home using XAMPP 1.8.2 while at work I've been using 1.7.2. I get the following error

Fatal error: Call to undefined function session_is_registered() in C:\xampp\htdocs\loginscript\session1.php on line 5

What I have on line 5.

if(!session_is_registered(username)){
header("location:index.php");
}

I would imagine it having to do something with pHp version? Cheers

A user has requested to see my code..

<?php 
session_start()
//--- Authenticate code begins here ---
//checks if the login session is true
if(!session_is_registered(username));{
header("location:index.php");
}
$username = $_SESSION['username'];

// --- Authenticate code ends here ---


 include ('header.php'); ?> 
  • 写回答

4条回答 默认 最新

  • dou4624 2014-07-09 09:55
    关注

    As pointed out by Halloei in the comments, you said at home you are using Xampp 1.8.2 and at work 1.7.2 - if you have a look at the Xampp version history 1.8.2 comes with PHP 5.4 whereas 1.7.2 comes with PHP 5.3 and the session_is_registered function was DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. This is the cause of the error you are seeing.

    To correct this you can update your code to something like the following:

    <?php 
    session_start();
    
    //--- Authenticate code begins here ---
    
    //checks if the login session is true
    if (!isset($_SESSION['username']))
    {
        header("location:index.php");
    }
    $username = $_SESSION['username'];
    
    // --- Authenticate code ends here ---
    
    include ('header.php'); 
    ?> 
    

    This uses isset to check if the value username is set in the session array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失