skip to Main Content

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(xampptmpsess_4p70knkr6lb7r9ha0pitktl3fe, O_RDWR) failed: No such file or directory (2) in <b>D:foundationtestssrcassetsphplogin.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start(): Failed to read session data: files (path: xampptmp) in <b>D:foundationtestssrcassetsphplogin.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(xampptmpsess_14rr40ahtg7rbgb20fvqocet83, O_RDWR) failed: No such file or directory (2) in <b>D:foundationtestssrcassetsphplogin.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start(): Failed to read session data: files (path: xampptmp) in <b>D:foundationtestssrcassetsphplogin.php</b> on line <b>2</b><br />

4

Answers


  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";
    
    Login or Signup to reply.
  2. <b>Warning</b>: session_start(): open(xampptmpsess_4p70knkr6lb7r9ha0pitktl3fe, O_RDWR) failed: No such file or directory (2) in <b>D:foundationtestssrcassetsphplogin.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:foundationtestssrcassetsphplogin.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:foundationtestssrc 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.

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
  4. I had the same problem. I finally figured out it was caused by me copying the .htaccess file from cPanel. If you’re using cPanel and have the same .htaccess file on your local XAMPP server, look for this line…

    BEGIN cPanel-generated php ini directives, do not edit

    The code below it sets up the php.ini values for the version of PHP installed on cPanel, and something in there is interfering with XAMPP. Remove that block of code (you don’t need it with XAMPP) and that should fix your problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search