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

jacklove
Release: 2023-03-27 12:46:01
Original
3868 people have browsed it

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;
}
}
Copy after login

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!

Related labels:
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!