Using get method, the data is carried out through the URL
which is visible and is insecure when compared with post method.
$_GET
.This data submitted can be accessed in the form using GET Method by $_GET
global variable.
[php]
<html>
<body>
<form action="#" method="get">
Name : <input type="text" name="name" />
Email : <input type="text" name="email" />
Contact : <input type="text" name="contact" />
<input type="submit" name="submit" value="Submit"></input>
</form>
<?php
if( $_GET["name"] || $_GET["email"] || $_GET["contact"])
{
echo "Welcome: ". $_GET[‘name’]. "<br />";
echo "Your Email is: ". $_GET["email"]. "<br />";
echo "Your Mobile No. is: ". $_GET["contact"];
}
?>
</body>
</html>
[/php]
Output:
$_POST
.This data submitted in the form can be accessed using POST Method by $_POST
global variable.
[php]
<html>
<body>
<form method="post" action="<?php echo $_SERVER[‘PHP_SELF’];?>" name="User-details">
Name : <input type="text" name="name" />
Mobile : <input type="tel" name="phone" />
<input type="submit" name="submit" value="Send" />
</form>
<?php
if ($_POST[‘submit’] == "Send")
{
$name = $_POST[‘name’];
$mobile = $_POST[‘mobile’];
if (empty($name)&& empty($mobile))
{
echo "Name & Mobile Number is empty";
}
else
{
echo $name;
echo $mobile;
}
}
?>
</body>
</html>
[/php]
Output:
The PHP saves all the variables in an array called as $GLOBALS["varible_name"]
.
[php]
<html>
<body>
<form method="post" action="" name="User-details">
Name : <input type="text" name="name" />
Mobile : <input type="tel" name="phone" />
<input type="submit" name="submit" value="Send" />
</form>
<?php
if ($_POST[‘submit’] == "Send")
{
$name = $_REQUEST[‘name’];
$mobile = $_REQUEST[‘mobile’];
if (empty($name)&& empty($mobile))
{
echo "Name & Mobile Number is empty";
}
else
{
echo $name;
echo $mobile;
}
}
?>
</body>
</html>
[/php]
Output:
[php]
<?php
echo $_SERVER[‘PHP_SELF’];
echo "<br>";
echo $_SERVER[‘SERVER_NAME’];
echo "<br>";
echo $_SERVER[‘HTTP_HOST’];
echo "<br>";
echo $_SERVER[‘HTTP_REFERER’];
echo "<br>";
echo $_SERVER[‘HTTP_USER_AGENT’];
echo "<br>";
echo $_SERVER[‘SCRIPT_NAME’];
?>
[/php]
Output: