GET and POST in PHP
Hello everyone, in this article we are going to talk about passing data methods in PHP. We will see here GET and POST methods. We will send and receive datas with these two methods in PHP language.Now let's begin.
Firstly I want to talk about GET method.
GET is a PHP global method for keeping datas which submitted with HTTP GET method. This method can be reached all location of the scripts. The GET method can be reached from the URL. So this methods look inside the URL. If you want to show the query datas to the user, you should use this method.
Related URL:
Our requested link is test.php?name=Burak&surname=TUFAN
Related PHP Code:
if( $_GET["name"] and $_GET["surname"] ) {
echo "Welcome " . $_GET['name'] . " " . $_GET['surname'] ;
exit();
}
The output of the this code will be like below:
Welcome Burak TUFAN
Now let's talk about POST method.
POST method is a PHP global method to read data which submitted via HTTP POST method. You can reach this method from everywhere of the project. If you do not want to display the datas that you want to sent to target page you should use this method.
Related URL:
Our requested link is test.php
Related PHP Code:
if( $_POST["name"] and $_POST["surname"] ) {
echo "The user is " . $_POST['name'] . " " . $_POST['surname'] ;
exit();
}
If we sent the same datas with HTTP POST method the output of the this code will be like below:
The user is Burak TUFAN
That is all in this article.
Have good transferring data.
Burak Hamdi TUFAN.
Comments