Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a website that uses session variables (in PHP) to know if the visitor is entering the website or not. If he's new, then I redirect him to the detected language. But if he's not new, you let him go wherever he wants to (even the pages in other languages).

The problem is that the variable used to achieve this ($_SESSION["knownvisitor"]) is not persistent. I've tested the same website in other server and it works just fine, so I'm pretty sure it's a sessions config problem. The problematic server is an Ubuntu Server 12.04.4 with Apache 2.2.22 and PHP 5.3.10.

The sessions are stored in "/var/lib/php5", and I can see the files there but they are empty. The session files belong to "www-data" and have the following rights "-rw-------". The directory, in the other hand, belongs to "root" and has these rights "drwx-wx-wt".

I tried using "session_write_close()" before redirecting, as recommended in some forums, with no luck. The redirection is like "header('Location: [URL]')".

Here's the code of the script so you can understand its basic behavior. This is what I put in the beginning of all the files in my web:

function detectedlang($availlangs)
 return $detectedlang;


if (!isset($_SESSION["knownvisitor"]))
 $detectedlang = detectedlang(array("en", "es"));
 $_SESSION["knownvisitor"] = true;
share|improve this question
up vote 2 down vote accepted

You said that /var/lib/php5/session is owned by root and has permissions drwx-wx-wt. This means that all users can write to the directory, but only root can read. The result is that PHP can create session files, but cannot go back and read them later. This appears to be why your sessions are failing.

Fix the ownership and permissions so that www-data can both read and write (rwx). For instance:

chgrp www-data /var/lib/php5/session
chmod g+rwx /var/lib/php5/session
share|improve this answer
Hi, thanks! First, the directory is "/var/lib/php5". Inside of it are the session files. And then, it actually worked!! Thank you! – Diego Mar 30 '14 at 19:36
Thanks @michael-hampton For me the directory is /var/lib/php/5.6/session After i changed the permission and the user now its working fine. – Mahendran Sakkarai Sep 18 '15 at 17:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.