Jump to content

[SOLVED] Sessions


eacollie

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.