0

I've went through various threads about this problem and couldn't find a solution.

I'm using the following code:

<?php
session_start();
ini_set('display_errors', 'on');
error_reporting(-1);
session_name("hello");
$_SESSION['username'] = "name";
echo $_SESSION['username'];
echo session_id();
if (is_writable(session_save_path()))
{
    echo "writable";
}
?>  

This is the output:

name771e6d83a8578e2dbadac64dc62b5788writable

Yet the session ID output keeps changing on every page refresh.

It is happening in all browsers I tried (Chrome, IE, FF).

In none of the browsers I couldn't locate a PHPSESSID cookie that is supposed to be sent from my domain.

Since the output yields writable, this shouldn't be a permission problem.

These are my php.ini settings:

enter image description here

session_auto_start is set to 0, like I guess it should be.

What can be causing this problem?

I'm trying to learn sessions, started with this simple code and can't get over this issue.

Another note: As you can see, I've set error reporting, and I don't get any special errors when I test this code on my VPS server. However, when I run the same code on some shared hosting account that I have on another server, I'm getting a headers already sent on line 2 error. I don't what exactly is making the difference, but I intend to run my project only on my VPS server anyway.

rockyraw
  • 1,125
  • 2
  • 15
  • 36
  • Locate and fix the `headers already sent` error. Even if there is no error message displayed on the other server, the error itself might still be present, and prevent the script from properly setting the session id cookie. – CBroe Nov 20 '15 at 12:29
  • @CBroe I'm a newbie and really have no clue what might be causing this error. I've read a thread about that error, but couldn't tell. I posted the whole code here, so where else can this come from? – rockyraw Nov 20 '15 at 12:36
  • That error has been broadly discussed already. And the error message already tells you where the first output was generated. – CBroe Nov 20 '15 at 12:44
  • @CBroe It might have been discussed buy I couldn't figure what is it that I should do from that discussion. I don't understand the error message - where are headers sent first time and when are they being sent second time in my code? how to control that? – rockyraw Nov 20 '15 at 12:59
  • http://stackoverflow.com/a/8028987/1427878 should tell you all you need to know. – CBroe Nov 20 '15 at 13:02
  • @CBroe Already looked at it before posting the thread, that's a long list and I couldn't figure out what is relevant. besides, that list doesn't really offer a solution, it just says what might be causing this. I need a way to fix the above 5 lines of code. – rockyraw Nov 20 '15 at 13:31

0 Answers0