Sessions

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'] ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2008
 
Posts: n/a
Default 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



Reply With Quote
  #2 (permalink)  
Old 05-05-2008
sarika
 
Posts: n/a
Default Re: Sessions

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
Reply With Quote
  #3 (permalink)  
Old 05-05-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Sessions

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
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0