christofurr Posted July 19, 2007 Share Posted July 19, 2007 Just started studying PHP sessions a few minutes ago. I created three small pages to test a session. The first - sessiontest1.php5 : <html> <body> <form action="sessiontest2.php5" method="post"> <input type="text" name="A" /> <input type="submit" /> </form> </body> </html> The second - sessiontest2.php5 : <?php session_start(); $_SESSION['A']=$_POST['A']; ?> <html> <body> <?php echo $_SESSION["A"]; ?> <p><a href="http://www.froobscape.com/sessiontest3.php5">TEST</a></p> </body> </html> The third - sessiontest3.php5 : <html> <body> <?php echo $_SESSION["A"]; ?> </body> </html> Why doesn't the third echo the form input? Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/ Share on other sites More sharing options...
pocobueno1388 Posted July 19, 2007 Share Posted July 19, 2007 You need to put session_start() at the top of the page to maintain the session. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302547 Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 <?php session_start(); ?> <html> <body> <?php echo $_SESSION["A"]; ?> </body> </html> You need a call to session_start() on each page using sessions. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302548 Share on other sites More sharing options...
akitchin Posted July 19, 2007 Share Posted July 19, 2007 i'll also point out that you don't necessarily need to name your pages .php5. .php suffices these days. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302549 Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 i'll also point out that you don't necessarily need to name your pages .php5. .php suffices these days. That would highly depend upon the server. Allot of places are offering support for php4 and php5 and file extensions are a good way to handle this. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302556 Share on other sites More sharing options...
christofurr Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks, Poco and Thorpe. I'm beginning to dislike W3schools. Many of their tutorials don't explain things fully. And I'm not so sure about that, Akitch. One of my scripts kept giving me errors until I revised the extension. Maybe it's my host. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302557 Share on other sites More sharing options...
akitchin Posted July 19, 2007 Share Posted July 19, 2007 my mistake, i forgot that a lot of hosts make that distinction these days. ignore my post. Link to comment https://forums.phpfreaks.com/topic/60814-solved-need-session-help/#findComment-302564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.