0

I have the following PHP code:

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 />

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).

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

EDIT: 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';

Result =>

<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 />
Narktor
  • 917
  • 9
  • 26

3 Answers3

3

<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 />

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.

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. Create a directory in your codebase (somewhere in D:\foundationtests\src I guess) that's outside DOCUMENT_ROOT.

  2. Configure session.save_path before you call session_start().

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

Álvaro González
  • 135,557
  • 38
  • 250
  • 339
  • 1
    Changing php.ini from `session.save_path = "\xampp\tmp"` to `session.save_path = "C:\xampp\tmp"` has worked for me! Thanks! – Lorenzo Magon Feb 12 '22 at 16:33
1

session_start(); should always be the first line of code in your project.

Using relative paths will get you into trouble. Try using an absolute path with $_SERVER['DOCUMENT_ROOT'], then dictate where the file is.

require_once $_SERVER['DOCUMENT_ROOT']."/connectToDatabase.php";
  • And @baryon123 if your `DOCUMENT_ROOT` comes up empty, refer to this answer: https://stackoverflow.com/a/7131859/2960971 ... or https://stackoverflow.com/a/15000656/2960971 – IncredibleHat Aug 22 '19 at 14:03
  • can you please show us a complete error, like screenshot –  Aug 22 '19 at 14:19
0

Just create a folder "xampp/tmp" in your root directory where all your projects are. For example:

I have xampp installed (as default) on my C:/ and All Projects root directory I have is D:/ So I created a folder structure like this: D:/xampp/tmp

Aldan
  • 529
  • 6
  • 20
Jangir
  • 1
  • 2