eacollie Posted July 8, 2009 Share Posted July 8, 2009 I don't know much about PHP, but want to use it to retain information from a form and I believe I need to use sessions to do this. I have a form in a php page that starts with session_start(); at the top of the page. In the form, I've set the inputs as (for example): <input name="email" type="text" id="email" value="<?php echo isset($_SESSION['ReservationForm']['email']) ? htmlentities($_SESSION['ReservationForm']['email'], ENT_COMPAT, "UTF-8") : '' ?>" /> The form action is another php file which also has session_start(); at the top. $email = $_REQUEST['email']; And in the html code: email:</td><td><?php echo $_SESSION['ReservationForm']['email']; ?> This works OK and it displays the form data on the second page. However, on this second page, I have a PayPal button where the user can add an item to a shopping cart. When the shopping cart is displayed and the user "continues shopping" back to page 2, the session data is not displayed. I know I'm missing something essential (for sure), but don't know what it is. Can anyone help? Thanks so much! Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/ Share on other sites More sharing options...
trq Posted July 8, 2009 Share Posted July 8, 2009 have you got a call to session_start() on all pages that need to access the $_SESSION array? Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/#findComment-870744 Share on other sites More sharing options...
eacollie Posted July 8, 2009 Author Share Posted July 8, 2009 Yes, the two php pages. Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/#findComment-870746 Share on other sites More sharing options...
eacollie Posted July 8, 2009 Author Share Posted July 8, 2009 The first page (page1.php) contains the form. The form's action is page2.php. Both these pages start with session_start(); However, when the user selects to pay with PayPal, they are directed to https://www.paypal.com/us/cgi-bin/webscr. Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/#findComment-870751 Share on other sites More sharing options...
eacollie Posted July 8, 2009 Author Share Posted July 8, 2009 Maybe it's a concept that I'm not understanding... On page1.php, when the user enters an email address in the form and then clicks the submit button, this is saved into a session variable, right? On the next page, page2.php, that session variable is retrieved with: $_SESSION['ReservationForm']['email'] = $_POST['email']; This variable is displayed on the same page with: <?php echo $_SESSION['ReservationForm']['email']; ?> However, when the user clicks on the PayPal button and is brought to another page, and then clicks "continue shopping" and is brought back to page2.php the session variable does not display. If I set the session variable on page2.php, it will display after being redirected from PayPal. Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/#findComment-870754 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 The session breaks when leaving the site, because a new session is created. I'd recommend using cookies to solve that issue. Link to comment https://forums.phpfreaks.com/topic/165138-solved-sessions/#findComment-870756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.