title: Session variables not persistent in PHP5/Apache2/Ubuntu12
body: <p>I couldn't find this specific problem around. 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).</p>
  
  <p>The problem is that the variable used to achieve this <code>($_SESSION["knownvisitor"])</code> 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.</p>
  
  <p>The sessions are stored in <code>/var/lib/php5</code>, and I can see the files there but they are empty. The session files belong to <code>www-data</code> and have the following rights <code>-rw-------</code>. The directory, in the other hand, belongs to "root" and has these rights <code>drwx-wx-wt</code>.</p>
  
  <p>I tried using <code>session_write_close()</code> before redirecting, as recommended in some forums, with no luck. The redirection is like <code>header('Location: [URL]')</code>.</p>
  
  <p>Does anyone have a clue? Thank you!</p>
  
  <p>EDIT: I'll add the code of the script so you can understand it's basic behaviour. This is what I put in the beginning of all the files in my web:</p>
  
  <pre><code>function detectedlang($availlangs)
  {
   // FUNCTION STUFF HERE TO FIND OUT WHICH IS THE LANGUAGE OF THE VISITOR
   return $detectedlang;
  }
  
  session_start();
  
  if (!isset($_SESSION["knownvisitor"]))
  {
   $detectedlang = detectedlang(array("en", "es"));
   $_SESSION["knownvisitor"] = true;
   header("Location: http://www.mysite.com/".$detectedlang);
  }
  </code></pre>