PHP session_start 错误(找不到这样的文件或目录)
PHP session_start error (no such file or directory found)
我是 PHP 的新手,我正在尝试创建一个登录系统,其中用户名通过会话存储在 PHP cookie 中。所以通过视频教程我了解到我使用 session_start();启动 cookie 会话,然后在满足条件时设置变量。我正在使用 XAMPP 来测试我的 PHP,因此当我加载页面时,出现此错误:
Warning: session_start() [function.session-start]: open(Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in C:\Users------\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 19
Warning: Unknown: open(----\Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (----\Desktop\xampp\tmp) in Unknown on line 0**
我的 XAMPP 文件中确实有一个临时文件夹,其中指定不要删除此文件夹,因为 PHP 创建会话时必须存在该文件夹。
这是我的 PHP 代码:
<?php
session_start ();
if (isset($_POST["submit"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$check = false;
$information = fopen("user_information.txt", "r");
while (!feof($information)) {
$content = explode(":", rtrim(fgets($information, 1024)));
if ($username == $content[0] && ($password) == $content[1]) {
$check = true;
break;
}
}
fclose($information);
if ($check) {
define('BASE_URL', 'index.php');
header('Location: ' . BASE_URL);
$SESSION["username"] = $username;
}
else {
define('BASE_URL', 'login.php');
header('Location: ' . BASE_URL);
}
}
?>
谢谢
配置错误。
检查您的 php.ini 文件中的以下行:
session.save_path = "/tmp"
或者在您的 PHP 脚本中:
session_save_path('/home/example.com/sessions');
该行告诉 PHP 会话文件的保存位置。
作为运行服务器的系统用户需要对此文件夹具有写权限。
我是 PHP 的新手,我正在尝试创建一个登录系统,其中用户名通过会话存储在 PHP cookie 中。所以通过视频教程我了解到我使用 session_start();启动 cookie 会话,然后在满足条件时设置变量。我正在使用 XAMPP 来测试我的 PHP,因此当我加载页面时,出现此错误:
Warning: session_start() [function.session-start]: open(Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in C:\Users------\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 19
Warning: Unknown: open(----\Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (----\Desktop\xampp\tmp) in Unknown on line 0**
我的 XAMPP 文件中确实有一个临时文件夹,其中指定不要删除此文件夹,因为 PHP 创建会话时必须存在该文件夹。 这是我的 PHP 代码:
<?php
session_start ();
if (isset($_POST["submit"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$check = false;
$information = fopen("user_information.txt", "r");
while (!feof($information)) {
$content = explode(":", rtrim(fgets($information, 1024)));
if ($username == $content[0] && ($password) == $content[1]) {
$check = true;
break;
}
}
fclose($information);
if ($check) {
define('BASE_URL', 'index.php');
header('Location: ' . BASE_URL);
$SESSION["username"] = $username;
}
else {
define('BASE_URL', 'login.php');
header('Location: ' . BASE_URL);
}
}
?>
谢谢
配置错误。
检查您的 php.ini 文件中的以下行:
session.save_path = "/tmp"
或者在您的 PHP 脚本中:
session_save_path('/home/example.com/sessions');
该行告诉 PHP 会话文件的保存位置。
作为运行服务器的系统用户需要对此文件夹具有写权限。