Introduction
There are basically four ways to do this: pass the variable in the URL, through a session, via a cookie, or with an HTML form. The method you choose depends on the situation and what best fits your needs at the time, we are basically discussing in this article passing variables through a URL.
The first method of passing variables among pages is through the page's URL. You have undoubtedly seen URLs such as this:
http://localhost/get.php?id=123
This an example of passing variable values through the URL. It requests that the article with the ID number of "123" be chosen for the "get.php" program. The text after the URL is called the query string. You can also combine variables in URLs by using an ampersand (&), as in this example:
http://localhost/get.php?id=123&language=english
This asks to retrieve the file with an ID of "123" and the language equal to "english". There are a few disadvantages to passing variables though a URL; they are:
- Everyone can see the values of the variable, so passing sensitive information is not really very secure using this method.
- The user can arbitrarily change the variable value in the URL and try deferent combinations, leaving your web site potentially open to showing something you did not intend to be shown.
- A user might also pull up inaccurate or old information using a saved URL with older variables embedded in it (from a bookmark, for example).
Variables that you pass around in this way are accessible in your PHP code through the special $_GET array. The variable name that appears in the URL is used as a key, so to retrieve the value of "id" you would reference $_GET['id'], or to retrieve the value of language you would reference $_GET['language'].
Example
<html>
<head>
<title>my compny info-<?php echo $_GET['name'];?></title>
</head>
<body>
<?php
echo 'My company name is ';
echo $_GET['name'];
echo '<br>';
$No = 8506800799;
echo 'Contact no is ';
echo $No;
?>
</body>
</html>
Save this file a "get.php".
<html>
<head>




Join the conversation! Your thoughts help the community grow.