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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题