name 2 common methods for passing data between scripts Solut

name 2 common methods for passing data between scripts .

Solution

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>
echo $_GET[\'id\']; // output 2489

echo $_GET[\'tom\']; // output tom


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

$id=$_POST[\'id\'];
$password=$_POST[\'password\'];

Collecting data submitted by either GET or POST method
$id=$_REQUEST[\'id\'];
$password=$_REQUEST[\'password\'];


Every scripting language pages has its own way of receiving the data from the URL
$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.

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


Passing variables through query string


$pid=$nt[product_id];
echo \"<a href=product-detail.php?product_id=$pid>Product Details</a>\";
You can directly display like this also.
echo \"<a href=\'product-detail.php?product_id=$nt[product_id]\'>Product Details</a>\";
Chang of data while passing through URL
There 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)
Security issues while posting data through URL
The most common type of security problem in using data from URL is injection attack. We must sanitize the date before using inside our script or generating any query to manage database.

name 2 common methods for passing data between scripts .SolutionThere are different ways by which values of variables can be passed between pages. One of the wa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site