Sessions



I need help. This is frustrating!
My impression of sessions is once the $_SESSION['variable'] is set, the
$_SESSION['variable'] is available on all pages as long as the
session_start() is on the top of each page.

I have used sessions a years ago successful, but I am having a problem that
I cannot figure out. I appreciate the help.

page1.php
<?php
session_start()
echo session_id();
?>
<html>
<form name="form1" method="post" action= "page2.php">
form1 with <input name="variable"> variable = 'name'
</html>
Page1 calls page2.php by submit form1
page1 echoes .....1234 the session_id() number

page2.php
<?php
session_start()
echo session_id();
$_SESSION['myname'] = $_POST['variable'];
echo $_SESSION['myname'};
?>
<html>
<form name="form2" method="post" action= "page3.php">
form2 calls page3.php with submit
</html>
Page2 calls page3.php by submit form2, the $_SESSION['myname'] is not in
the form2
page2 echoes .... 1234 the session_id() number
page2 echoes name therefore $_SESSION['myname'] = name which is correct

page3.php
<?php
session_start()
echo session_id();
echo $_SESSION['myname'};
?>
<html>
........
</html>
page3 echoes .... 1234 session_id() is correct for all pages
page3 echoes nothing therefore $_SESSION['myname'] = is empty the value was
not carried through to page 3

Two questions:

1. What can cause the session variable to loose the value even though the
session_id() is carried through?
2. I want to use $_SESSION['myname'] on a page out of sequence, that is,
skipping one page. Can this be done? Isn't session variables suppose to be
available to all pages? not only sequential apges.

Thanks for the help. I know I am missing something, but what?

Ken



.



Relevant Pages