gpt4 book ai didi

PHP session_start 错误(找不到这样的文件或目录)

转载 作者:行者123 更新时间:2023-12-05 01:46:44 25 4
gpt4 key购买 nike

我是 PHP 的新手,我正在尝试创建一个登录系统,其中用户名通过 session 存储在 PHP cookie 中。所以通过视频教程我了解到我使用 session_start();启动 cookie session ,然后在满足条件时设置变量。我正在使用 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 必须在其中创建 session 。这是我的 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 session 文件将保存在哪里。

运行服务器的系统用户需要对此文件夹具有写入权限。

关于PHP session_start 错误(找不到这样的文件或目录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34025899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com