The second page should be
<?php
session_start();
echo { $_SESSION['foo'] . "<BR>\n");
echo { $_SESSION['bar'] };
?>
you're missing the session_start()
You need it on every page that you plan to use session
on.
--- John Nichel <[EMAIL PROTECTED]> wrote:
> Shaun Campbell wrote:
> > I've got a problem getting sessions to work and I
> wondered if anyone could
> > offer any advice.
> >
> > The example I am using is to get one page to set
> variables in a session and
> > then use another page to retrieve them. I am
> using 4.3.4RC2 and prior to
> > that 4.3..3 on Win2k with IE6 and Apache 1.3.22.
> >
> > The code is:
> >
> > page1.php
> > ----------
> > <?php
> > session_start();
> >
> > $_SESSION['foo'] = 'Hello';
> > $_SESSION['bar'] = 'World';
> >
> > ?>
> > <HTML>
> > <HEAD>
> > <TITLE>
> > </TITLE>
> > </HEAD>
> > <BODY>
> >
> > Variables set in session - hopefully???
> >
> > <?php
> > echo "foo = {$_SESSION['foo']}<BR>";
> > echo "bar = {$_SESSION['bar']}";
> > ?>
>
> Get rid of the "foo =" and the "bar =". when you
> use the single equals
> sign, you're setting value....
>
> <?php
> echo { $_SESSION['foo'] . "<BR>\n");
> echo { $_SESSION['bar'] };
> ?>
>
> > <form action="page2.php" method="post">
> > <input type="submit" name="submit" value="Page 2"
> />
> > </form>
> >
> > </BODY>
> > </HTML>
> >
> > page2.php
> > ----------
> > <?php
> > session_start();
> > echo "foo = {$_SESSION['foo']}";
> > echo "bar = {$_SESSION['bar']}";
> > ?>
>
> Same here....
>
> <?php
> echo { $_SESSION['foo'] . "<BR>\n");
> echo { $_SESSION['bar'] };
> ?>
>
> > On page 1 I am seeing the session variables
> displayed correctly i.e. Hello
> > World and I can see a session file created in my
> temp directory with the
> > correct values in there. However, when I display
> page 2 the variables are
> > always displayed blank and what seems to happen is
> that a new empty session
> > file is created in my temp directory. It's as
> though the second page is not
> > related to the same session somehow. I've also
> tried lots of other examples
> > from books and on the net and I still can't get
> sessions to work.
> >
> > Am I doing something wrong in connecting the two
> pages although I don't
> > close the browser down at all between the two?
> >
> > Any ideas would be greatly appreciated.
> >
> > Thanks
> >
> > Shaun Campbell
>
>
>
> --
> By-Tor.com
> It's all about the Rush
> http://www.by-tor.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php