newbie session code problem

This is a discussion on newbie session code problem within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Here are snips from 2 pages; tst1.php and tst2.php tst1.php echos the session id, then sets and ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-15-2008
Xylene2301
 
Posts: n/a
Default newbie session code problem

Here are snips from 2 pages; tst1.php and tst2.php

tst1.php echos the session id, then sets and echos a session variable called
username.

pressing a button on tst1.php submits to a form tst2.php which echos the
session id (successfully) and attempt to echo the username session vaiable
(fails). Why not?

The code is running on a shared server at Dreamhost, a really big hosting
svc. It's running php 4.4.7, register_globals is on,session support is
enabled.

Thanks for any help.

Here are the pages:

tst1.php************************************

<?php
session_start(); // start the session
$_SESSION['username'] = "Goody";
echo $PHPSESSID ."<br>";
echo $_SESSION['username'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>tst1</title>
</head>

<body>

<form method="post" name="ThisForm" action="tst2.php">
<button onclick="submit()">t2</button>
</form>

</body>
</html>


tst2.php************************************

<?php
echo $PHPSESSID ."<br>";
echo $username;
echo $_SESSION['username'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>tst2</title>
</head>

<body>

<form method="post" name="ThisForm" action="tst1.php">
<button onclick="submit()">t1</button>
</form>

</body>
</html>


Reply With Quote
  #2 (permalink)  
Old 01-15-2008
Christoph Jeschke
 
Posts: n/a
Default Re: newbie session code problem

Xylene2301:

> pressing a button on tst1.php submits to a form tst2.php which echos
> the session id (successfully) and attempt to echo the username session
> vaiable
> (fails). Why not?


You missed

> tst1.php************************************
> <?php
> session_start(); // start the session

^^^^^^^^^^^^^^^^

> tst2.php************************************
>
> <?php


here.

Greetings
Christoph

--
Today is Setting Orange, the 15th day of Chaos in the YOLD 3174

Reply With Quote
  #3 (permalink)  
Old 01-15-2008
Xylene2301
 
Posts: n/a
Default Re: newbie session code problem

It's a little hard to see. I've numbered the lines and the
session_start(); for tst1.php is on line 2 under the <?php.
I'm pretty sure the session is running because both scripts echo the same
$PHPSESSID.

tst1.php

1 <?php
2 session_start(); // start the session
3 $_SESSION['username'] = "Goody";
4 echo $PHPSESSID ."<br>";
5 echo $_SESSION['username'];
6 ?>
7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
8 "http://www.w3.org/TR/html4/loose.dtd">
9 <html>
10 <head>
11 <title>tst1</title>
12 </head>
13
14 <body>
15
16 <form method="post" name="ThisForm" action="tst2.php">
17 <button onclick="submit()">t2</button>
18 </form>
19
20 </body>
21 </html>


tst2.php

1 <?php
2 echo $PHPSESSID ."<br>";
3 echo $username;
4 echo $_SESSION['username'];
5 ?>
6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
7 "http://www.w3.org/TR/html4/loose.dtd">
8 <html>
9 <head>
10 <title>tst2</title>
11 </head>
12
13 <body>
14
15 <form method="post" name="ThisForm" action="tst1.php">
16 <button onclick="submit()">t1</button>
17 </form>
18
19 </body>
20 </html>


Reply With Quote
  #4 (permalink)  
Old 01-15-2008
Xylene2301
 
Posts: n/a
Default Re: newbie session code problem

If someone else wanted to run the scripts, I'd be very curious as to what
results you'd get.


"Christoph Jeschke" <spam@knurd.de> wrote in message
news:478c5d69$0$9110$9b4e6d93@newsspool2.arcor-online.net...
> Xylene2301:
>
>> pressing a button on tst1.php submits to a form tst2.php which echos
>> the session id (successfully) and attempt to echo the username session
>> vaiable
>> (fails). Why not?

>
> You missed
>
>> tst1.php************************************
>> <?php
>> session_start(); // start the session

> ^^^^^^^^^^^^^^^^
>
>> tst2.php************************************
>>
>> <?php

>
> here.
>
> Greetings
> Christoph
>
> --
> Today is Setting Orange, the 15th day of Chaos in the YOLD 3174
>



Reply With Quote
  #5 (permalink)  
Old 01-15-2008
Xylene2301
 
Posts: n/a
Default Re: newbie session code problem

Ohhhh! I get it!
Tst2.php has to have a session_start() as well!

Thanks!!


"Christoph Jeschke" <spam@knurd.de> wrote in message
news:478c5d69$0$9110$9b4e6d93@newsspool2.arcor-online.net...
> Xylene2301:
>
>> pressing a button on tst1.php submits to a form tst2.php which echos
>> the session id (successfully) and attempt to echo the username session
>> vaiable
>> (fails). Why not?

>
> You missed
>
>> tst1.php************************************
>> <?php
>> session_start(); // start the session

> ^^^^^^^^^^^^^^^^
>
>> tst2.php************************************
>>
>> <?php

>
> here.
>
> Greetings
> Christoph
>
> --
> Today is Setting Orange, the 15th day of Chaos in the YOLD 3174
>



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 09:08 PM.


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