Home >Backend Development >PHP Tutorial >PHP's simplest implementation method for verifying logged in users (basic form user verification)

PHP's simplest implementation method for verifying logged in users (basic form user verification)

jacklove
jackloveOriginal
2018-05-22 14:43:463917browse

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:

In PHP development, how to determine whether the previous script has finished running during scheduled execution?

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!

Statement:
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