Super global variables are built-in variables that are always available in all scopes.
PHP $_REQUEST
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.
The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag. In this example, we point to this file itself for processing form data. If you wish to use another PHP file to process form data, replace that with the filename of your choice. Then, we can use the super global variable $_REQUEST to collect the value of the input field:
Example
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
'WEB > PHP' 카테고리의 다른 글
[고도몰 Pro+] SFTP 접속이 안됨과 동시에 문제 해결하기 (0) | 2023.05.25 |
---|---|
FTP 설정 방법 - 고도몰 (0) | 2023.05.18 |
The difference between "public" and "public static"? (0) | 2021.11.23 |
PHP 실행 지연(delay) 시키기 (0) | 2021.11.23 |
mb_substr (0) | 2021.09.13 |