我一直试图找出为什么我的代码无法在家里使用 XAMPP 1.8.2 的电脑上运行,而在工作中我一直使用 1.7.2。我收到以下错误
Fatal error: Call to undefined function session_is_registered() in C:\xampp\htdocs\loginscript\session1.php on line 5
我在第 5 行有什么。
if(!session_is_registered(username)){
header("location:index.php");
}
我想它必须对 pHp 版本做一些事情?干杯
用户请求查看我的代码..
<?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'); ?>
最佳答案
正如 Halloei 在评论中指出的那样,您说在家中使用 Xampp 1.8.2,在工作中使用 1.7.2 - 如果您查看 Xampp version history 1.8.2 附带 PHP 5.4,而 1.7.2 附带 PHP 5.3 和 session_is_registered
该函数自 PHP 5.3.0 起已弃用,自 PHP 5.4.0 起已删除
。这就是您所看到的错误的原因。
要纠正此问题,您可以将代码更新为如下所示:
<?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');
?>
这使用 isset
检查 session 数组中是否设置了值username
。
关于pHp session 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24649608/