How to send a GET request from PHP?


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:

https://www.google.com/search?q=hello

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

  • main.php:<!DOCTYPE html>
  • <html>
  •   
  • <head>
  •     <title>Get request</title>
  • </head>
  •   
  • <body>
  •     <form action="welcome.php" method="get">
  •       
  •         <table>
  •             <tr>
  •                 <td>First Name:</td>
  •                 <td><input type="text" name="firstnamename"></td>
  •             </tr>
  •           
  •             <tr>
  •                 <td>E-mail:</td>
  •                 <td><input type="text" name="emailid"></td>
  •             </tr>
  •           
  •             <tr>
  •                 <td></td>
  •                 <td style="float:right;"><input type="submit"></td>
  •             </tr>
  •         </table>
  •     </form>
  • </body>
  •   
  • </html>                    
  • welcome.php:<html>
  •   
  • <body>
  •     Welcome to GeeksforGeeks!<br>
  •       
  •     First Name: <?php echo $_GET["firstname"]; ?><br>
  •     Email Address: <?php echo $_GET["emailid"]; ?>
  • </body>
  •   
  • </html>

Output:

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


Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya