$_GET and $_POST is generally used in the forms to transfer data from one file to another file. Both the variables are kind of same except when we need to keep our data secure we use $_POST and generally in the form we use $_POST.
We will see the explanation by a example:
In this form we have used “get” method and we will see the output below:
As we can see we have used the method “get” in the form and in the output page of testform.php we can see the input given, also with that in the URL box we can see the details which we have provided in the form.html.
If we use “post” method in the form.html we will see the difference below:
As we can see in the URL box there is no such details provided which we can see while using “post” method.
Super global variable is a variable which can be used in two different files for manipulation.
For example we have a variable “a” in File1.php and we need to print, edit or any manipulation needed to be done in the variable in File2.php then we have to use Super Global Variable as a variable in File1.php.
Types of Super Global Variablein PHP:-
To see the use of variable $_GET and $_POST follow the link given below:
$_REQUEST can catch the data which is sent using both POST & GET methods whereas $_GET and $_POST can catch the data which is sent by get and post.
Use of variable $_SERVER
When we use $_SERVER we can extract extra data from the client when the form is filled. Extra data in a sense we can extract:
– HTTP Connection
– Server Information
– Host Information
– URL Information
We can see it with the example given below:
Now when we insert the data in the form.html we will see the following information:
Use of $_COOKIE variable:
Cookies are small file that the server embeds on the user’s computer each time the same computer requests a page with a browser it will send the cookie too. With PHP, we can both create and retrieve cookie values.
To create a cookie we need to run the following command: