【发布时间】:2015-11-16 00:48:21
【问题描述】:
我在执行网站上收到此通知:
Notice: Undefined variable: _SESSION in *PATH* on line 25这行代码$_SESSION["Registration_Error"] = TRUE;为什么是未知的$_SESSION-Variable?
他们是否改变了在 Session-Variable/Cookie 中保存数据的方式?
在 Google 上找不到好东西。只是这个http://php.net/manual/de/book.session.php#116217,我认为这没有多大帮助。
想法?
编辑:
完整代码
<?php
session_start();
function __autoload($class_name) {
include "../backend/classes/$class_name.php";
}
$Connection = new DB_Connect();
$User_Functions = new User_Functions();
$UserName = filter_input(INPUT_POST, "UserName");
$Password = filter_input(INPUT_POST, "Password");
$Mail = filter_input(INPUT_POST, "Mail");
$date = new DateTime();
$Registration_Date = $date->format("Y-m-d H:i:s");
if (!empty($UserName) && !empty($Password) && !empty($Mail)) {
if (!$User_Functions->User_Exists($UserName)) {
$Password_hashed = password_hash($Password, PASSWORD_DEFAULT);
$Query = "INSERT INTO wordsusers (`wordsUserName`, `wordsUserPassword`, `wordsUserMail`, `wordsUserRegDate`) VALUES (:wordsUserName, :wordsUserPassword, :wordsUserMail, :wordsUserRegDate)";
$Parameter = array(":wordsUserName" => $UserName, ":wordsUserPassword" => $Password_hashed, ":wordsUserMail" => $Mail, ":wordsUserRegDate" => $Registration_Date);
$Registered = $Connection->Execute_PDO_Command($Query, $Parameter);
} else {
$_SESSION["Registration_Error"] = TRUE;
header("Location: ../index.php");
}
}
【问题讨论】:
-
你在脚本开头是否调用了
session_start()? -
是的,在第一行;)
-
如果没有多年的警告,他们不可能做出如此剧烈、不兼容的改变。您的脚本中一定有错字或其他内容。
-
您收到
Headers already sent警告了吗? -
使用十六进制编辑器检查您的脚本,确保其中没有多余的、不可见的字符。