Page 1 of 1

Not setting session

Posted: Wed Dec 24, 2003 5:58 pm
by pinehead18
<?php
// Cookie testing page

if ($submit) {
session_start();
if(!isset($_SESSION['vars'])) {
$vars['pic'] = "pic";
}
}
?>
<form method=post action=sessions.php>
<input type=submit name=submit value='set session'>
</form>

--------------------------------------------------------------------------------



This is suppose to set a session.. However it does not .. Any suggestions?



PHP:
--------------------------------------------------------------------------------

<?PHP

session_start();
$vars = $_SESSION['vars'];
$whatever = $vars['pic'];

?>

--------------------------------------------------------------------------------



That is session2.php where i view the session that the script above created.

Thank you for any help you can provide.

- Anthony

Posted: Wed Dec 24, 2003 6:12 pm
by amarquis
session_start(); needs to stand on your page before any other header... this means that session_start(); must be called before any headers are sent out !

If the above script is included in another page it's very likeley that the other page already sent headers out - so you should call session_start() there...

You can also look at this post that helped me to understand how it works with forms... :wink:

http://www.phpb.com/forums/read.php?f=6&i=168&t=161

Hope this helps...