what is php superglobal variable array

尊渡假赌尊渡假赌尊渡假赌
Release: 2023-06-07 13:03:27
Original
835 people have browsed it

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.

what is php superglobal variable array

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[&#39;name&#39;];
$age = $_GET[&#39;age&#39;];
echo "Welcome $name! You are $age years old.";
Copy after login

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[&#39;name&#39;];
$age = $_POST[&#39;age&#39;];
echo "Welcome $name! You are $age years old.";
Copy after login

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[&#39;name&#39;];
$age = $_REQUEST[&#39;age&#39;];
echo "Welcome $name! You are $age years old.";
Copy after login

4. The $_COOKIE array is used to access cookies that have been stored on the client computer

// send_cookie.php
setcookie(&#39;username&#39;, &#39;John&#39;, time() + (86400 * 30), "/"); // 设置 cookie
echo &#39;Cookie sent.
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!