A quick and easy way to pass PHP variables between pages
We know this post is a little off topic considering it doesn’t pertain to average designer, but it certainly is web related so we figured we would share it. There are many ways to pass variables between pages whether your writing the variable to a session, passing arrays between pages, passing the variables in links, or using the method that we will describe below which is using the post method. This example should be relatively easy to follow for even the true beginners. The source files used in this example are available for download (free) at the bottom of this post.
Step 1. Create index.php
Using any code/text editor, create a file “index.php”. This index.php file will contain the form we are going to use. Add your form fields (as shown in the screenshot).
Step 2. Add a name to each field
Now you are going to add a unique name to each field so we can identify them when processing the form.
Step 3. Create field_process.php
Now we will assign a corresponding variable to the variables that we have sent post from the previous page. At this point we’ve finished the task of passing the variables from one page to another.
Step 4. Show the results on the field_process.php page
Now we are going to take it a step further and show the posted results on the field_process.php page using the echo function.
DOWNLOAD SOURCE:
No related posts.











Great tutorial. In practical implementation you’ll have to make sure the variables you echo to HTML are HTML entity encoded.
eg:
Character encoding has to also be taken into consideration.
eg:
This makes sure the htmlentities are UTF-8 encoded and thus further prevents exploits based on encoding.
Leave your response!