This is a discussion on Sessions within the PHP Language forums, part of the PHP Programming Forums category; I need help. This is frustrating! My impression of sessions is once the $_SESSION['variable'] is set, the $_SESSION['variable'] ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
On May 5, 11:52*am, <d...@wi.rr.com> wrote:
> 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 supposeto be > available to all pages? not only sequential apges. > > Thanks for the help. *I know I am missing something, but what? > > Ken U must be doing something wrong because when i try this code it works fine after correcting some syntex error at echo $_SESSION['myname'}; '}' should be ']'. Check your code once again there will be some other issue |
|
|||
|
dadk@wi.rr.com wrote:
> 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? Could be several things. The most common is something ahead of your session_start() call - anything, even whitespace, will cause the headers to be sent and session_start() to fail. Another common problem is that your webserver userid does not have write access to the temporary directory, or the temporary directory is set incorrectly. There are others. In your php.ini file, ensure you have: error_reporting=E_ALL display_errors=on This should show you the error in your code. > 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. > There is no "sequence" of pages. Each page is an individual transaction. Anything set in the session is available until unset or the session is terminated. > Thanks for the help. I know I am missing something, but what? > > Ken > > > > -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |