Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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:
What is the purpose of php.ini file ?
Next article icon

What is the use of the $_REQUEST variable in PHP ?

Last Updated : 28 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Uses of PHP $_REQUEST:

  • The PHP $_REQUEST is a PHP superglobal variable that is used to collect the data after submitting the HTML forms as the $_REQUEST variable is useful to read the data from the submitted HTML open forms.
  • $_REQUEST is an associative array that by default contains contents of an $_GET, $_POST, and $_COOKIE.
  • The variables in a $_REQUEST super variable are obtained to the HTML scripts through GET, POST, and COOKIE inputs, so it could be changed by the remotely associated user and can’t be trusted again.
  • The presence $_REQUEST variable and the suited orders of $_REQUEST are variables listed in the array is declared similar to the PHP request_order, and variables_order configuration directives are it.
  • PHP $_REQUEST is the featuring PHP superglobal variable which is used to collect data after submitting the HTML forms in the browser
  • PHP’s $_REQUEST is widely used to collect information that is after submitting from HTML browsed forms.
  • The $_REQUEST function is used to get the form information sent with its POST method and the other GET method.

Approach: The example demonstrates an HTML form with the input field and within having to submit button. When a user submits the information by clicking on the button “Submit”, the filled data is sent to the file i.e. examined with actions attributes of the <form> tag within it

We aim the file itself for preprocessing form data as we use another PHP file to preprocess a form data, replacing that with occurring filename of our choice. We use the PHP $_REQUEST super global variable to collect the value of the input field from it.

Example:

HTML

<!DOCTYPE html>
<html>
    
<body>
   <!--Defining Form-->
   <h1 style="color:green">GeeksforGeeks</h1>
   <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
      Name: <input type="text" name="pname">
      <input type="submit">
   </form>    
      
    <?php
  
        // Getting $REQUEST METHOD
        if ($_SERVER["REQUEST_METHOD"]=="POST") {
            $name = htmlspecialchars($_REQUEST['pname']); 
  
            // Collecting the value of input field from it
            if (empty($name)) {
                echo "Name is empty";
            } 
            else {
               // Printing the entered data
                echo $name;    
           }
        }
    ?>
</body>
</html>
                      
                       

Output:

For The String “GeeksforGeeks”



Next Article
What is the purpose of php.ini file ?

K

khurpaderushi143
Improve
Article Tags :
  • Geeks Premier League
  • PHP
  • Web Technologies
  • Geeks-Premier-League-2022
  • PHP-Questions

Similar Reads

  • What is the use of the @ symbol in PHP?
    The at sign (@) is used as error control operator in PHP. When an expression is prepended with the @ sign, error messages that might be generated by that expression will be ignored. If the track_errors feature is enabled, an error message generated by the expression and it will be saved in the varia
    1 min read
  • What are the different scopes of variables in PHP ?
    Variable Scopes: The scope of a variable is defined as its extent in the program within which it can be accessed, i.e. the scope of a variable is the portion of the program within which it is visible or can be accessed. Depending on the scopes, PHP has three variable scopes. Local variables: The var
    3 min read
  • What is the use of $GLOBALS in PHP ?
    In this article, we will discuss $GLOBALS in PHP. $GLOBALS is a superglobal variable used to access global variables from anywhere in the PHP program. PHP stores all global variables in an array called $GLOBALS[index]. Syntax: $GLOBALS['index']=value;value is the input value.The index is the unique
    1 min read
  • What is the purpose of php.ini file ?
    In this article, we will learn about the purpose of the php.ini file. At the time of PHP installation, php.ini was a special file provided as a default configuration file. Purpose of php.ini file:It’s a very essential configuration file that controls what a user can or cannot do with the website.Eac
    5 min read
  • What is the use of array_count_values() function in PHP ?
    In this article, we will discuss array_count_values() function & its usage in PHP, along with understanding its basic implementation through the illustrations. The array_count_values() function is used to count all the values inside an array. In other words, we can say that array_count_values()
    2 min read
  • When should one use require_once() vs require() in PHP ?
    In this article, we will learn, when should one use the require_once() method and when to use require() method in PHP. require() Method: PHP require() is a library or built-in function in PHP. It is generally used in situations where we want to include a file in the PHP code or program. The require(
    3 min read
  • What are pre-request scripts in Postman, and how are they used?
    Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It has the ability to make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, converting the API to code for various languages(like JavaScript, Pytho
    2 min read
  • What are the differences between PHP constants and variables ?
    PHP Constants: PHP Constants are the identifiers that remain the same. Usually, it does not change during the execution of the script. They are case-sensitive. By default, constant identifiers are always uppercase. Usually, a Constant name starts with an underscore or a letter which is followed by a
    2 min read
  • How to register a variable in PHP session ?
    The PHP session is required so that you can store the user information and use it on different pages of the browser. Approach: It creates a session with the name or any other useful information you want to store and access on different pages. Even after your page is closed you can access the informa
    3 min read
  • Servlet - Client HTTP Request
    When the user wants some information, he/she will request the information through the browser. Then the browser will put a request for a web page to the webserver. It sends the request information to the webserver which cannot be read directly because this information will be part of the header of t
    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