Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to send a GET request from PHP?

  • Last Updated : 16 Apr, 2019

There are mainly two methods to send information to the web server which are listed below:

  • GET Method: Requests data from a specified resource.
  • POST Method: Submits data to be processed to a specified resource.

Get Method: The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ‘?’ character.
For example:

Program: This program illustrates the use of GET method in PHP:

  • main.php:

    <!DOCTYPE html>
        <title>Get request</title>
        <form action="welcome.php" method="get">
                    <td>First Name:</td>
                    <td><input type="text" name="firstnamename"></td>
                    <td><input type="text" name="emailid"></td>
                    <td style="float:right;"><input type="submit"></td>
  • welcome.php:

        Welcome to GeeksforGeeks!<br>
        First Name: <?php echo $_GET["firstname"]; ?><br>
        Email Address: <?php echo $_GET["emailid"]; ?>


  • Before Clicking the button:
  • After Clicking the button:

The above code uses the Get method to send data to the server. On clicking the submit button, the URL of the page changes to something from http://localhost/test/main.php to http://localhost/test/welcome_get.php?firstname=Geeks&

Here, we can see that the URL contains a question mark, and the name of the input field and the value entered in those fields after the http://localhost/test/main.php link. However, it must be kept in mind that GET requests are only used to request data, not to modify. Also, the GET method is restricted to send up to 1024 characters only. GET can’t be used to send binary data, like images or word documents, to the server, and it should not be used to send any password or sensitive information to the server. POST method should be used for such an operation.

My Personal Notes arrow_drop_up
Recommended Articles
Page :