Page 1 of 1

Can not get sessions to work.

Posted: Thu Jan 20, 2005 11:50 am
by Mattias1975
Hello!

I have two files. index.php calling action.php from a html form.


index.php
************

<html>
<body>

<?php
session_start();

if (!isset($_SESSION['s'])) {
$_SESSION['s'] = 'test';
}

session_write_close();
?>

<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
</html>
</body>

action.php
*************

<html>
<body>

<?php
session_start();
echo $_SESSION['s'];
?>.

Hi <?php echo $_SESSION['name']; ?>.
You are <?php echo $_POST['age']; ?> years old!

</body>
</html>


Calling the session_start(); function causes this message and the action.php never recives the session s:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/local/apache2/index.php:4) in /usr/local/apache2/index.php on line 5

What is wrong?
Thank you.

Posted: Thu Jan 20, 2005 11:56 am
by feyd
your pages have text output before the php can send the headers.

read here: viewtopic.php?t=1157