Home >Backend Development >PHP Problem >what is php superglobal variable array
Super global variables in PHP are a type of predefined global variable array that can be used in scripts and can be accessed without declaration by the developer. These arrays include $_GET, $_POST, $_REQUEST, $_COOKIE, etc.
Operating system for this tutorial: Windows 10 system, php8.1.3 version, Dell G3 computer.
PHP Super Global Array, also known as PHP predefined array, is built into the PHP engine and does not need to be redefined by developers. When a PHP script runs, PHP automatically places some data in a super global array.
1. The $_GET array is used to collect form data submitted through the GET method, usually in the form of URL parameters
<form action="process.php" method="get"> Name: <input type="text" name="name"><br> Age: <input type="text" name="age"><br> <input type="submit"> </form> // process.php $name = $_GET['name']; $age = $_GET['age']; echo "Welcome $name! You are $age years old.";
2. The $_POST array is used to collect form data submitted through the POST method. , can be used to process sensitive data
<form action="process.php" method="post"> Name: <input type="text" name="name"><br> Age: <input type="text" name="age"><br> <input type="submit"> </form> // process.php $name = $_POST['name']; $age = $_POST['age']; echo "Welcome $name! You are $age years old.";
3. The $_REQUEST array contains the contents of GET, _POST, and $_COOKIE. Can be used to collect data after HTML form submission or obtain data from the browser address bar.
<form action="process.php" method="post"> Name: <input type="text" name="name"><br> Age: <input type="text" name="age"><br> <input type="submit"> </form> // process.php $name = $_REQUEST['name']; $age = $_REQUEST['age']; echo "Welcome $name! You are $age years old.";
4. The $_COOKIE array is used to access cookies that have been stored on the client computer
// send_cookie.php setcookie('username', 'John', time() + (86400 * 30), "/"); // 设置 cookie echo 'Cookie sent.
The above is the detailed content of what is php superglobal variable array. For more information, please follow other related articles on the PHP Chinese website!