Can not get sessions to work.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mattias1975
Forum Newbie
Posts: 1
Joined: Thu Jan 20, 2005 11:44 am

Can not get sessions to work.

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your pages have text output before the php can send the headers.

read here: viewtopic.php?t=1157
Post Reply