From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Storing data in session variables

Storing data in session variables - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Storing data in session variables

The order confirmation page of the Hansel and Petal site processes the post array after the user submits the form from the build a bouquet page. But the script in this page doesn't do anything to preserve the data. So there would be no data for this Confirm Order button to process. Now, we won't be going as far as building a complete e-commerce site in this course. But let's see how to use session variables to preserve data from page to page. So, let's go to the editing program. And it's order.php that we've got open. Before you can use session variables, you need to create a PHP session with session start. And we're going to need the session variables in this page even if it's accessed without clicking the bouquet submit button. So, sessions start must go outside the if statement at the top. So, let's put it on line two. Session_start, then an empty pair of parentheses, and a semi colon. That gives us access to a session and to session variables. The data that needs to be preserved…

Contents