Super global variables are a very powerful and common variable type in PHP programming. They store various information related to the running status of the program, such as user input, server environment variables, etc. In this article, we will introduce how to use PHP super global variables, as well as some common super global variables and their functions.
1. The concept and function of super global variables
Super global variables are predefined variables in PHP. They can be used anywhere in the script without scope restrictions. Super global variables are used to store information in the program running environment, such as HTTP request information, server information, etc. when the script is executed. The predefined super global variables in PHP are as follows:
2. Use super global variables
In PHP programming, using super global variables is very simple. You only need to use the super global variable name directly in the code. The following is sample code for using super global variables:
<?php $name = $_GET['name']; echo "Hello, $name!"; ?>
<?php $name = $_POST['name']; echo "Hello, $name!"; ?>
<?php session_start(); // 开始会话 $_SESSION['username'] = 'john'; // 保存会话变量 echo $_SESSION['username']; // 获取会话变量 ?>
<?php $filename = $_FILES['file']['name']; $filetype = $_FILES['file']['type']; $filesize = $_FILES['file']['size']; echo "Filename: $filename<br>"; echo "File type: $filetype<br>"; echo "File size: $filesize bytes"; ?>
3. Notes
In short, super global variables are a very powerful and common variable type in PHP programming. They can easily obtain and process the running environment information of the program, such as user input, server environment variables, etc. When using super global variables, you must pay attention to the safety of the input values to ensure the safety and stability of the program.
The above is the detailed content of How to use super global variables in PHP programming?. For more information, please follow other related articles on the PHP Chinese website!