Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session_start fails

Tags:

php

session

xampp

I'm trying to start the session in a header page in my webiste. But it seems there might be some sort of bug because it fails with the following error:

Warning: session_start() [function.session-start]: open(\xampp\tmp\sess_a7430aab4dd08d5fc0d511f781f41fe5, O_RDWR) failed: No such file or directory (2) in D:\Development\PHP\tt\Include\header.php on line 3

I'm using the default settings for xampp, everything is straight out of the box. For some reason its failing to open the file. however when i go to the directory with the session files in it, the files are there, they are just empty. Is this a bug? or am I doing something wrong?

php version 5.2.8

like image 697
The.Anti.9 Avatar asked Mar 22 '09 05:03

The.Anti.9


People also ask

What does session_start () do in PHP?

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.

Do I need to call session_start on every page?

It must be on every page you intend to use. The variables contained in the session—such as username and favorite color—are set with $_SESSION, a global variable. In this example, the session_start function is positioned after a non-printing comment but before any HTML.

What is PHP session_start () and Session_destroy () function?

session_destroy() function: It destroys the whole session rather destroying the variables. When session_start() is called, PHP sets the session cookie in browser. We need to delete the cookies also to completely destroy the session. Example: This example is used to destroying the session.

How do I keep a PHP session alive?

Using ajax you can call a php script that refreshes your session every 10 minutes. :) This is as far as i can go to "exact". <? php session_start(); // store session data if (isset($_SESSION['id'])) $_SESSION['id'] = $_SESSION['id']; // or if you have any algo. ?>


2 Answers

First stop the Xampp Server.

session.save_path = "\xampp\tmp"

and change it to look like this

session.save_path = "C:\xampp\tmp"

Restart the Xampp Server.

That’s it now your session should work as expected.

like image 128
Selular88 Avatar answered Sep 20 '22 00:09

Selular88


This means that you don't have the correct permissions to either read or write the files in the temp directory.

If you on linux then do this

sudo chmod -R 755 \xampp\tmp //or should it be 775

On windows do this as an administrator

attrib -r -a C:\xampp\tmp /S
like image 31
UnkwnTech Avatar answered Sep 20 '22 00:09

UnkwnTech