what are the superglobals?
superglobals are the specially predefined global array variables.
These are mainly used to get information from one page to another page on our website.
$_GET
$_GET is a PHP super global variable that is used to collect data after submitting an HTML form with method="get".
if the get method is used in a form, the data filled in the fields of the forms will be shown after the submission.
$_GET can also collect data sent in the URL.
$_GET can also collect data sent in the URL.
<?php
if (isset($_GET['submit']))
{
$a=$_GET['n1'];
echo$a;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" >
<input type="text" name="n1">
<input type="text" name="n2">
<input type="submit" name="submit">
</form>
</body>
</html>
$_POST
{
$a=$_GET['n1'];
echo$a;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" >
<input type="text" name="n1">
<input type="text" name="n2">
<input type="submit" name="submit">
</form>
</body>
</html>
$_POST
POST requests do not remain in the browser URL.
$_POST is used to get information after the submission of a form when the method is post.
<?php
if (isset($_POST['submit'])) {
$a=$_POST['n1'];
echo$a;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="n1">
<input type="text" name="n2">
<input type="submit" name="submit">
</form>
</body>
</html>
if (isset($_POST['submit'])) {
$a=$_POST['n1'];
echo$a;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="n1">
<input type="text" name="n2">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if (isset($_REQUEST['submit'])) {
$a=$_REQUEST['n1'];
echo$a;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" >
<input type="text" name="n1">
<input type="text" name="n2">
<input type="submit" name="submit">
</form>
</body>
</html>
note:
1. stop the resubmission on refreshing the page:
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
2. stop the back button of the browser:
function preventBack()
{
window.history.forward();
}
setTimeout("preventBack()", 0);
window.onunload = function ()
{
null
};
0 Comments