1

My first page is:

<?php

session_start();

$_SESSION['test'] = 'testSession';

?>

Other page is:

<?php

session_start();

echo $_SESSION['test'];

?>

There is no output on the second page. The error log outputs:

[30-Oct-2013 12:13:53] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

Are there any ideas as to what the problem might be? The session variables can be outputted fine on the first page (when I tested), but not on the second. Thank you.

user2938543
  • 327
  • 1
  • 6
  • 12
  • Is this the 1st code at the top of your page? Do you have a space, or line return before your opening php tag - `_ – Sean Oct 30 '13 at 18:22
  • One more thing - You should pass SSID somehow to that another page. GET. POST. COOKIES... – Kamiccolo Oct 30 '13 at 18:39

1 Answers1

2

If you are using sessions in your application then you must start the session at the very top of your page, you must avoid spaces or extra line spaces after

<?php

and

session_start();

Write your code as follows:

<?php
session_start();

$_SESSION['test'] = 'testSession';

?>

and on second page,

<?php
session_start();

echo $_SESSION['test'];

?>

Hope this solves the problem, and if still not then you may use following technique:

<?php
ob_start();
session_start();

$_SESSION['test'] = 'testSession';

?>

and on second page,

<?php
ob_start();
session_start();

echo $_SESSION['test'];

?>
Ali
  • 5,021
  • 4
  • 26
  • 45