Solved

Send PHP variables through multi page form

Posted on 2010-08-27
8
1,197 Views
Last Modified: 2012-06-21
I am creating a small customer portal to capture invoice information.  I have created 4 pages for the user to walk through.
1. customer information
2. invoice information
3. desired sending method
4. confirm information and send

i would like for the data from each page to be carried throughout the system until the end.  I am currently pulling the information from page 1 to page 2 using a PHP variable and hidden form elements on page 2.  Then passing those hidden form elements to page 3 and so on.

Is that the best practice for passing the data from page to page or should i work some session variables?  If so, can someone give me some guidance on how to setup session variables and the capabilities of session variables.  thanks in advance.
0
Comment
Question by:axessJosh
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:honestman31
Comment Utility
0
 
LVL 2

Accepted Solution

by:
morleys earned 500 total points
Comment Utility
Storing this information in the session is the easiest way to manage data through a series of pages.
Early in your script (before you output anything) call: session_start();
You can then store and retrieve data using the the session array:
       $_SESSION['views'] = 1;
Generally you'll have a block at the start of the code which extracts data from the session into local variables with a usefull default
       $viewCnt = ISSET($_SESSION['views']) ? (int)$_SESSION['views'] : 0
If you have the same set of variables you will want to put that into a common subroutine.
On exit update the session with the new values
      $_SESSION['views'] = $viewCnt
0
 
LVL 2

Author Comment

by:axessJosh
Comment Utility
I know just enough about PHP to be dangerous, but does the Session variables automatically get passed from page to page based on the session_start(); code?  What tells the second page that the session is still active?
0
 
LVL 10

Expert Comment

by:honestman31
Comment Utility
but does the Session variables automatically get passed from page to page based on the session_start()  -->YES

hat tells the second page that the session is still active --> session_start()
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 2

Expert Comment

by:Tekati68
Comment Utility
An easier way for you to do this that would not rely on cookies which the user can have turned off is to simply setup hidden form variables on each new page.

For example lets say on customer info form you get name, address, phone then on invoice information form simply setup hidden fields with the values from form 1.  You can name them the same except just hidden and at the end when you confirm information and send it will simple send all the fields.

This works if they hit the back button as well but has the added benefit that if they have cookies turned off it will still work!
0
 
LVL 2

Expert Comment

by:morleys
Comment Utility
The session information is stored on the web server. A cookies is added to the response headers which provides the identity of the session and when returned from the client on the POST is used to reference the correct session data.

One advantage of session information is that you can store data that you don't want to send to and from the client so as to reduce the ability to hack the application.

Sessions do require that the client browser support cookies and its often a good idea to verify that in an early page of the site with a suitable warning that the site requires cookies.
0
 
LVL 2

Author Comment

by:axessJosh
Comment Utility
so then that presents a new question,  which of the options would be the best and most effecient, session variables with its need for cookies to be enabled or hidden input fields variables?
0
 
LVL 2

Expert Comment

by:morleys
Comment Utility
Depends on your needs and the audience you are addressing. I have usually found that most people keep cookies turned on and the use of the session gives you lot of flexibility to store information securely. If you put the information into hidden fields you expose that data to your users and permit them to manipulate it. Alternatively the use of hidden fields allows you to support non-cookie users, does not require your users to respond in a fixed length of time (the session will generally have a small timeout period). You have to balance the various attributes of the methods against the needs of your application and the environment you will be operating in. Personally, I usually go for sessions unless there is some prevailing need not to.  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress type image upload 10 24
Creating a slider 12 31
session dropped in IE 10 18
What is the Best Editor for PHP Development ? 5 16
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now