PHP simplest authentication login user (basic form user authentication) Implementation method

Source: Internet
Author: User
Form validation is often seen in PHP and will be explained in this article.

The following code can implement basic form submission, user authentication.

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 what you want to do next.

Determine the source HTTP Authentication login user

if (!isset ($_server[' Php_auth_user ')) {header ("Www-authenticate:basic realm=\" My Private area\ "); Header (" http/1.0 401 Unauthorized ");p rint" 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 ");p rint" You need Valid credentials to get access!\n "; exit;}}

This article explains the form validation knowledge, more relevant knowledge, please pay attention to the PHP Chinese web.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.