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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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> |
|
|||
|
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 |
|
|||
|
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> |
|
|||
|
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 > |
|
|||
|
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 > |