Passing Values Between Pages (ASP and PHP)

From a Form

Using ASP or PHP you can easily pass values from a form on one page to be processed and form part of what is displayed on a subsequent page. To do this you need to make the ASP or PHP page the destination of the form's submit button by coding the name of that page into the action parameter of the form tag. There are two ways that the fields within your form can be passed to the following page and which of these two ways will be used depends on the method parameter. Using method="get" will pass the values of the fields in the form to the next page by adding them onto the end of the URL of the page you are calling while method="post" provides a more useful means of passing larger quantities of data.

When your visitor fills out the form and submits it they will be taken to the ASP or PHP page that you have specified as the next page to be displayed. This page can include the appropriate commands for whichever of the two languages that you are using to access all of the fields from the form on the previous page so as to display different content depending on the values entered, display the values themselves, or even to email the values or store them in a database on your server where they can be retrieved by this and other ASP or PHP pages on your site.

Between Pages

If you want to pass values between ASP or PHP pages without having to store the values in a database then you can use cookies to identify the individual visitors. ASP stores a Session Id in a cookie on the visitor's computer which it then can use to identify that same user on subsequent pages. To make use of this to pass a value between pages you can code the following, for example, on the page that is to pass a value to a later page:

 <% Response.Cookies("planet")="Mars" %>

The subsequent page can then retrieve this value using:

 <%= Request.Cookies("planet") %>

With PHP you can pass a value between pages you can code the following, for example, on the page that is to pass a value to a later page:

 setcookie ("TestCookie", $value);

This value can then be accessed as $HTTP_COOKIE_VARS['TestCookie'] on subsequent PHP pages.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate