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><formaction="welcome.php"method="get"><table><tr><td>First Name:</td><td><inputtype="text"name="firstnamename"></td></tr><tr><td>E-mail:</td><td><inputtype="text"name="emailid"></td></tr><tr><td></td><tdstyle="float:right;"><inputtype="submit"></td></tr></table></form></body></html>chevron_rightfilter_none -
welcome.php:
<html><body>Welcome to GeeksforGeeks!<br>First Name: <?phpecho$_GET["firstname"]; ?><br>Email Address: <?phpecho$_GET["emailid"]; ?></body></html>chevron_rightfilter_none
Output:
- 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&emailid;=abc%40geeksforgeeks.org
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.
Recommended Posts:
- How to send an email using PHPMailer ?
- PHP | Spreadsheet_Excel_Writer | send() Function
- PHP | Send Attachment With Email
- How to read any request header in PHP
- How to send HTTP response code in PHP?
- How to send a JSON object to a server using Javascript?
- How to configure XAMPP to send mail from localhost using PHP ?
- Send unlimited Whatsapp messages using JavaScript
- When to use Vanilla JavaScript vs jQuery ?
- How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ?
- How to animate scrollTop using jQuery ?
- How to select text nodes using jQuery ?
- Why require_once() function is so bad to use in PHP ?
- How to convert arguments object into an array in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



