session_start()导致错误:没有这样的文件或目录(新鲜的,可移植的XAMPP) [英] session_start() causes error: No such file or directory (fresh, portable XAMPP)

查看:37
本文介绍了session_start()导致错误:没有这样的文件或目录(新鲜的,可移植的XAMPP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下PHP代码:

include './globallyUsedFunctions/connectToDatabase.php';
include './globallyUsedFunctions/hashInput.php';
session_start();

由于某些原因,它会导致此错误:

For some reason, it causes this error:

<br />
<b>Warning</b>:  session_start(): open(\xampp\tmp\sess_4p70knkr6lb7r9ha0pitktl3fe, O_RDWR) failed: No such file or directory (2) in <b>D:\foundationtests\src\assets\php\login.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start(): Failed to read session data: files (path: \xampp\tmp) in <b>D:\foundationtests\src\assets\php\login.php</b> on line <b>2</b><br />

现在,我认为原因在于代码之外,因此以下是有关我的系统的一些信息:我有一个最新版本的免安装XAMPP,我在其中运行apache和mariaDB.这是在Windows 10计算机上以没有管理员权限的用户帐户运行的(这就是为什么我选择XAMPP的无安装版本).

Now I think that the reason for this lies outside the code, so here is some info about my system: I have the most recent version of a no-install XAMPP, I run apache and mariaDB in it. This is running on a windows 10 machine, on a user account without admin privileges (thats why I chose the no-install version of XAMPP).

该网站还在基于Webpack4,gulp和babel7的ZURB Foundation Framework(ZURB模板6.4)内部运行.

The website is also running inside the ZURB Foundation Framework (ZURB Template 6.4) which is based on webpack4, gulp and babel7.

我已经尝试过的替代方法:

Alternatives I already tried:

由代码构建者"建议(请参阅答案)

suggested by "code builders" (see answers)

session_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/globallyUsedFunctions/connectToDatabase.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/globallyUsedFunctions/hashInput.php';

结果=>

<br />
<b>Warning</b>:  session_start(): open(\xampp\tmp\sess_14rr40ahtg7rbgb20fvqocet83, O_RDWR) failed: No such file or directory (2) in <b>D:\foundationtests\src\assets\php\login.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start(): Failed to read session data: files (path: \xampp\tmp) in <b>D:\foundationtests\src\assets\php\login.php</b> on line <b>2</b><br />

推荐答案

< b>警告</b> ;: session_start():open(\ xampp \ tmp \ sess_4p70knkrr6lb7r9ha0pitktl3fe,O_RDWR)失败:< b> D:\ foundationtests中没有这样的文件或目录(2)\ src \ assets \ php \ login.php</b>在第< b> 2</b>< br/>

session_start()尝试向其写入数据的路径没有驱动器号.由于您是从 D:\ foundationtests \ src \ assets \ php \ login.php 运行代码,因此假定它也位于 D:.您说实际路径应位于 E:.这是问题所在.

The path where session_start() attempts to write its data to does not have a drive letter. Since you are running your code from D:\foundationtests\src\assets\php\login.php, it's assumed to be at D: as well. You say the actual path should be at E:. Here you are the problem.

我对第三方捆绑软件不熟悉(有时它们似乎会引起更多问题,无法解决),但是肯定会有一个 php.ini 文件,该文件中的不完整href ="https://www.php.net/manual/zh-CN/session.configuration.php#ini.session.save-path" rel ="nofollow noreferrer"> session.save_path 指令.找到并进行修复.

I'm not familiar with third-party bundles (some times they seem to cause more problems than they solve) but it'll surely has a php.ini file somewhere with an incomplete session.save_path directive. Find it and fix it.

除此之外,更好的长期解决方案是为每个应用程序启用自定义会话目录.机制大致相同:

Apart from that, a better long term solution is to enable a custom session directory for each application. The mechanism is roughly the same:

  1. 在您的代码库(我想在 D:\ foundationtests \ src 中的某个地方)中创建一个目录,该目录位于DOCUMENT_ROOT之外.

  1. Create a directory in your codebase (somewhere in D:\foundationtests\src I guess) that's outside DOCUMENT_ROOT.

配置 session.save_path ,然后再调用 session_start().

这还有一个额外的好处,即可以完全控制会话超时.

This has the added benefit of providing full control on session timeout.

这篇关于session_start()导致错误:没有这样的文件或目录(新鲜的,可移植的XAMPP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆