CodesJava

Easy learning with example program codes

PHP Form Get And Set


Superglobals are the functions that are accessible in any function, class or file. There is no specified scope or any special way to access the superglobals. PHP facilitates with two superglobals to create and to collect form data. These are:

$_GET:

It is an array of variables which is passed to the current script using the URL parameters.

 

$_POST:

 

It is an array of variables which is passed to the current script using the HTTP POST method.

Difference between GET and POST:

GET and POST are used to create an array to hold the name of the form controls as a key within the array and to hold the user fed data as the value of the respected key. The difference between the two are listed below:

GET POST
Information sent is visible to everyone. Information sent is invisible to others.
All the names and values are displayed in the URL. All the names and values are embedded inside the HTTP request body.
It has a limit of about 2000 characters on the amount of information to send. There is no limit on the amount of information to send, in case of POST.
It is possible to bookmark the page. It is not possible to bookmark the page.
GET should be used for sending non-sensitive data only. POST can be used for sending sensitive data also.
No advanced functionality available. Advanced functionality like multi-part binary input (while uploading files to server) is also available.

Example 1: To receive data from get request in PHP.
login.php:

<?php  
$name=$_GET["name"];//receiving name field value in $name variable  
echo "Welcome, $name";  
?>

form.html:

<!DOCTYPE html>
<html>
<body>
 
<form action="welcome.php" method="get">  
Name: <input type="text" name="name"/>  
<input type="submit" value="visit"/>  
</form> 
 
</body>
</html>

Example 2: To receive data from post request in PHP.
login.php:

<?php  
$name=$_POST["name"];//receiving name field value in $name variable  
$password=$_POST["password"];//receiving password field value in $password variable  
 
echo "Welcome: $name, your password is: $password".;  
?>

form.html:

<!DOCTYPE html>
<html>
<body>
 
<form action="login.php" method="post">   
<table>   
<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>  
<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>   
<tr><td colspan="2"><input type="submit" value="login"/>  </td></tr>  
</table>  
</form>   
 
</body>
</html>
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki