Form validation is often seen in php, and this article will explain it.
The following code can implement basic form submission and user verification.
The user name in the html page, php will be placed in $_SERVER['PHP_AUTH_USER']. The password is placed in $_SERVER['PHP_AUTH_PW'].
Hello world, you can implement the operations you want to perform next.
//Determine the source http to verify the logged in user
if (!isset($_SERVER['PHP_AUTH_USER'])) { header("WWW-Authenticate: Basic realm=\"My Private Area\""); header("HTTP/1.0 401 Unauthorized"); print "You need valid credentials to get access!\n"; exit; } else { if (($_SERVER['PHP_AUTH_USER'] == 'admin') && ($_SERVER['PHP_AUTH_PW'] == 'qwert!@#$%12345')) { echo "hello world"; } else { header("WWW-Authenticate: Basic realm=\"My Private Area\""); header("HTTP/1.0 401 Unauthorized"); print "You need valid credentials to get access!\n"; exit; } }
This article explains the relevant knowledge of form verification. For more related knowledge, please pay attention to the PHP Chinese website.
Related recommendations:
Detailed explanation of the difference and use of const and static in php
Detailed explanation of the use of php and its regular expressions
The above is the detailed content of PHP's simplest implementation method for verifying logged in users (basic form user verification). For more information, please follow other related articles on the PHP Chinese website!