PHP 5 $_POST and $_GET
PHP Superglobal Arrays
A superglobal array is a built - in PHP variable that is available in any scope, Different types of information are stored in different type of global variables
- It's useful information about the environment.
- It's allowed to access the form data.
- It's access the cookies.
- It's track the session.
PHP $_GET
PHP $_GET is used to passed data using HTTP protocol. Some about the $_GET superglobal array are following below.
- Which includes variables passed as part of URL.
- GET method handle small amounts of data.
- If you want to send sensitive data like password never used $_GET method.
- $_GET associative array used for accessing the sent information by GET method.
<?php if(isset($_POST['na'])) { $name = $_POST['na']; $lname = $_POST['na1']; echo "Your full name :" . $name." " .$lname; } ?> <html> <body> <form action="<?php $_PHP_SELF ?>" method="GET"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html>
- Example
- Run
PHP $_POST
$_POSt is very similar to $_GET method. Some about the $_GET superglobal array are following below.
- It's also used to collect form data.
- $_POST method handles large amount of data.
- The $_POST superglobal array can be used secure information like password.
<?php <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php $name = $_POST['fname']; echo $name; ?> </body> </html>
- Example
- Run