1

To avoid illegal use I check the login status at the beginning of the code. I do this as follows:

if (!isset($_SESSION['loggedin'])){
  header('Location:http://www.name.nl/prg/login.php');
  exit();
} 

This works. But if I use this code first it doesn't work.

ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT'])).'/name.nl/tmp');
session_start();
if (!isset($_SESSION['loggedin'])){
  header('Location:http://www.name.nl/prg/login.php');
  exit();
} 

Am I missing something? I looked for 2 days now, but can't find a reason/solution. It seems to me that the header function should work after ini_set and session_start. I mean it is common code?

Jos
  • 21
  • 2
  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – showdev Jun 03 '15 at 19:47

2 Answers2

1

Try this first: ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']).'/name.nl/tmp'));

(Move parentheses)

Try looking here: http://php.net/manual/en/function.session-save-path.php

Not sure if this will help or not but it seems related to where your session folder is at and then pointing to the proper directory/folder in your code.

The solution that worked for them: ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));

Your current session save:

ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT'])).'/name.nl/tmp');

0

Well I found the cause. I had an "echo statement" before the header statement. After deleting this statement it works fine. Thx for your comment anyway!

Jos
  • 21
  • 2