-3

I'm having trouble with session and header. First of all, they are both working on my local development computer. But after I published the website, they don't work there.

The first problem is about storing session data. I tried everything.

  • I wrote session_start() at the top of the page.
  • Checked if the folder is writable with is_writable(session_save_path()) method. Which returns true.

But still not working.

Second is about header("location: "). It works too on my localhost but not working on the server that I published the website.

What am I missing?

For example, at index.php, those lines don't work.

<?php
session_start();
if (empty($_SESSION['counter'])) {
    $_SESSION['counter'] = 0;
}
echo $_SESSION['counter'] ++;
?>

When I refresh the page, it doesn't increment the value.

arokh
  • 11
  • 2
  • Anything in the error log? What is the production set-up like? "doesn't work there" meaning the sessions aren't persistent, or not being set at all? – ʰᵈˑ Nov 11 '14 at 16:43
  • 1
    "Not working" is not a workable problem description. Figure out and describe in more detail **what you're doing** and what it **does or doesn't do**. Have you activated error reporting? Have you checked your error logs? – deceze Nov 11 '14 at 16:45
  • Having said that, you're very likely looking for this: http://stackoverflow.com/a/8028987/476 – deceze Nov 11 '14 at 16:46
  • I added error_reporting( E_ALL ); at the top but returns nothing. – arokh Nov 11 '14 at 16:49
  • Have you also added `ini_set('display_errors', true)`? Otherwise you won't see nothing. – deceze Nov 11 '14 at 16:53
  • Yes, it doesn't work too. – arokh Nov 11 '14 at 16:54

2 Answers2

1

Solved!

It seems the white spaces before session_start() were causing the problem. Removed them and now it works.

arokh
  • 11
  • 2
-1

I would check your page encoding. If you have notepad++ (if you don't, download it because it's awesome) use it to open the page and click encoding to see what it is. Make sure it is UTF-8 without BOM.