Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
$_GET and $_POST in PHP
Next article icon

$_GET and $_POST in PHP

Last Updated : 26 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In PHP, superglobals are built-in global arrays that provide access to certain data types, such as form inputs, session data, and URL parameters. Among the most commonly used superglobals in web development are $_GET and $_POST. These superglobals are used to collect data from HTML forms and URLs.

In this article, we will explore what $_GET and $_POST are, how they work, and their use cases in PHP programming.

What is $_GET ?

The $_GET superglobal is used to collect form data sent via the GET method. This method appends data to the URL as query parameters, which are visible to users in the browser’s address bar. Some of the features of the $_GET are:

  • Retrieves data sent to the server as part of the URL query string.
  • Useful for retrieving data that is visible to the user, such as search queries or parameters in a URL.
  • Data sent via $_GET is visible in the URL, making it less secure for sensitive information.
  • Accessed using associative array notation, e.g., $_GET['parameter'].

Syntax:

<?php echo $_GET['username']; // Outputs the value of the 'username' parameter from the URL ?>

Now, let us understand with the help of the example:

PHP
<html> <body>     <form action="index.php" method="get">     <label>username:</label><br>     <input type="text" name="username"><br>     <input type="submit" value="Log in"><br>     </form> </body> </html> <?php echo "{$_GET["username"]} <br>" ; ?> 

Output

Animationkk
$_GET Superglobals

In this example:

  • A form asks the user for a username and submits it via the GET method to index.php.
  • The form submits the data to the same page (index.php), allowing the same script to process the data.
  • The form includes a text input field for the username.
  • The submit button sends the form data when clicked.
  • After submission, PHP retrieves and displays the entered username using $_GET['username'].
  • Since the form uses the GET method, the form data (like the username) is appended to the URL as query parameters (e.g., index.php?username=anjali), making the username visible in the browser’s URL bar.

What is $_POST?

The $_POST superglobal is used to collect form data sent via the POST method. Unlike GET, the POST method sends data in the body of the HTTP request, so the data is not visible in the URL. Some of the features of the $_POST are:

  • Retrieves data sent to the server in the body of an HTTP request, typically from HTML forms submitted using the POST method.
  • Suitable for handling sensitive or large amounts of data as it's not visible in the URL.
  • More secure than $_GET for handling sensitive information like passwords.
  • Accessed using associative array notation, e.g., $_POST['field_name'].

Syntax:

<?php echo $_POST['username']; // Outputs the value of the 'username' parameter submitted via POST ?>

Now, let us understand with the help of the example:

PHP
<html> <body>     <form action="index.php" method="post">     <label>username:</label><br>     <input type="text" name="username"><br>     <input type="submit" value="Log in"><br>     </form> </body> </html> <?php echo "{$_POST["username"]} <br>" ; ?> 

Output

Animationkk
$_POST Superglobals

In this example:

  • A form asks the user for a username and submits it via the POST method to index.php.
  • The form submits the data to the same page (index.php), ensuring the data is processed on the same script.
  • The form includes a text input field for the username.
  • The submit button sends the form data when clicked.
  • After submission, PHP retrieves and displays the entered username using $_POST['username'].
  • Since the form uses the POST method, the form data is sent in the HTTP request body, not in the URL, so the username is not visible in the URL bar.

When to Use $_GET and $_POST

Use $_GET:

  • For data like search terms or filter criteria that don't need security.
  • Best for short data (due to URL length limits).
  • Useful when you need to share or bookmark URLs with parameters (e.g., search queries).
  • Typically used for retrieving data without modifying the server (e.g., reading data from a database).

Use $_POST:

  • Sensitive information (e.g., passwords, payment details) since it is not visible in the URL.
  • Suitable for forms with larger data, such as file uploads.
  • Use for submitting forms that change server-side data (e.g., registration forms).
  • Prevents data from being cached or stored in browser history.

$_GET vs $_POST

Both $_GET and $_POST are superglobals in PHP used to collect form data, but they differ in how and where the data is transmitted.

$_GET

$_POST

Data is visible in the URL

Data is hidden in the HTTP request body

Limited by URL length

Can handle large data sizes

Not secure (data is visible)

More secure, but still requires sanitization


Next Article
$_GET and $_POST in PHP

P

pankaj_gupta_gfg
Improve
Article Tags :
  • PHP

Similar Reads

    HTTP GET and POST Methods in PHP
    In this article, we will know what HTTP GET and POST methods are in PHP, how to implement these HTTP methods & their usage, by understanding them through the examples. HTTP: The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a r
    4 min read
    PHP Date and Time
    PHP provides functions to work with dates and times, allowing developers to display the current date/time, manipulate and format dates, and perform operations like date comparisons, time zone adjustments, and more.In this article, we'll discuss PHP date and time.Why are Date and Time Important in PH
    5 min read
    How to use PHP in HTML ?
    In this article, we will use PHP in HTML. There are various methods to integrate PHP and HTML, some of them are discussed below. You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <?php and the PHP end tag ?>. The code wrapped between these
    2 min read
    Variables and Datatypes in PHP
    A variable in PHP is a container used to store data. The value of a variable can change during program execution. PHP variables start with a dollar sign ($), followed by the variable name.$name = "GFG";$age = 30;Declaring Variables in PHPTo declare a variable, you simply use the dollar sign followed
    4 min read
    How to upload a file in PHP ?
    In this article, we will learn how to upload a file using PHP. Let us first understand some basic configurations. Approach: In your "php.ini" file, search for the "file_uploads" parameter and set it to "On" as mentioned below. file_uploads = On In the "index.html" file, the enctype must be multipart
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences