SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Passing variables with data between pages using URL

There are different ways by which values of variables can be passed between pages. One of the ways is to use the URL to pass the values or data. Here the biggest advantage is we can pass data to a different site even running at different servers. Any scripting language like ASP, JSP, PHP or Perl running at receiving end can process and collect the value from the query string or from the URL. Here one main concern is the data gets exposed in address bar of the browser and can be easily accessible by using browser history. So this is not a good idea to pass sensitive data like password through the URL to different pages or different sites. Here is an example of passing data through URL within a site.

<a href='page2.php?id=2489&user=tom'>link to page2</a>


When the above link is clicked, page2.php gets the variables id and user with data 2489 and tom respectively. The address of page2.php can be replaced with any site name and the same data can be passed to another site running in any server. Like this

<a href=http://www.sitename.com/index.php?id=2489&user=tom>Link to another site</a>


You can see in the above case the values can be posted to another site. Note that after the page name we are using question mark ( ? ) to start the variable data pair and we are separating each variable data pair with one ampersand ( & ) mark.

Submitting form values through GET method.
A web form when the method is set to GET method, it submits the values through URL. So we can use one form to generate an URL with variables and data by taking inputs from the users. The form will send the data to a page within the site or outside the site by formatting a query string.

<form method=GET action='http://www.anysite.com/index.php'>


Read more on difference between get and post method of form submission.

Every scripting language pages has its own way of receiving the data from the URL
While receiving the data based on the server settings the values will be available to the pages. Here in a server running PHP will have to see the global settings of the server on how to collect the data.

$id=$_GET['id'];
$user=$_GET['user'];


Same way in ASP environment running VB script the data can be collected and assigned like this

Id = Request.QueryString("id")
User = Request.QueryString(“user”)


Passing data within the site using URL
The same principle is used like above to send the data within the site using URL. A query sting can be formatted with a link or a form can be used with get method to pass variables between pages.

Passing the data between the site through URL
Like above data can be passed to different pages of sites using URL . The best use is directly linking to a page dip inside another site by formatting a query sting. Like this

<a href=http://www.sitename.com/viewtopic.php?id=5248>Linking to a topic</a>


Chang of data while passing through URL
The is a problem in sending data other than plain text through browser. Empty space and some characters like & if present in the data , will create problem. To maintain the data integrity we have to encode the data before sending them though URL and then decode them again to get back the original data. In PHP encode command is used and in ASP VBScript the command is Server.URLEncode(string)

Further readings
PHP Form Validation
PHP Email validation







Discuss this tutorial at forum


 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.