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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.