Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1208
  • Last Modified:

Send PHP variables through multi page form

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
axessJosh
Asked:
axessJosh
  • 3
  • 2
  • 2
  • +1
1 Solution
 
honestman31Commented:
0
 
morleysCommented:
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
 
axessJoshAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
honestman31Commented:
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
 
Tekati68Commented:
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
 
morleysCommented:
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
 
axessJoshAuthor Commented:
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
 
morleysCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now