Change language

How do I send a GET request from PHP?

There are basically two ways to send information to the web server, which are listed below:
  • GET method:requests data from the specified resource.
  • POST method:sends data for processing to the specified resource.
Get method:The GET method sends encoded user information appended to the request pages. The page and the encoded information are separated by a "?" the character. 
For example:
https://www.google.com/search?q=hello 
Program:This program illustrates the use of the GET method in PHP:
  • main.php: < 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:  
    Welcome to GeeksforGeeks!
    First Name: echo $_ GET [ "firstname" ]; ?>
    Email Address: echo $_ GET [ "emailid" ]; ?>  
    < / html >
Output:
  • Before pressing the button:
  • After clicking the button:
The above code uses the Get method to send data to the server. When the submit button is clicked, the page URL changes from http: //localhost/test/main.php to http: //localhost/test/welcome_get.php? Firstname = Geeks & amp; emailid = abc% 40engineerforengineer.orgHere we see that the URL contains a question mark, as well as the name of the input field and the value entered in these fields after the link http: // localhost / test /main.php. Keep in mind, however, that GET requests are only used to request data, not to modify it. Also, the GET method is limited to send only up to 1024 characters. GET cannot be used to send binary data such as images or text documents to the server, and should not be used to send any password or sensitive information to the server. The POST method should be used for such an operation.

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method