Browser Basic AUTH Way Certified phpMyAdmin Auto-login _php Tutorial

Source: Internet
Author: User
Tags chrome developer
This article to introduce the browser basic auth way authentication phpMyAdmin automatic login, there is a need to understand the students can enter the reference.

First, the demand
Automatic login PhpMyAdmin. The result is the ability to automatically log in to all Web pages that are certified using the Basic Auth method.

.
Second, phpMyAdmin four kinds of authentication login mode
1.config configuration file. Write the user name and password that are allowed to login directly in the config.inc.php configuration file.
2.cookie. The most common way to log in is by filling out the first page form.
3.http. HTTP Basic authentication mode, use the browser's pop-up dialog box to log in. The difference from the cookie approach is primarily the user experience.
4.signon. Single sign-on for system integration. User login to a system, do not have to lose the user name password can be one-click Login PhpMyAdmin.
Reference: Http://wiki.phpmyadmin.net/pma/Auth_types

The principle of signon should be the preferred solution to meet the needs, but the project development always have compromises and accommodation, to minimize interference in the operation of existing systems. In addition, in the implementation of Signon mode login, but also need to retain the original user input password login mode, that is, the alternative login scheme. This complicates the problem.

Third, what is the Basic Auth
The existing system uses the Basic Auth approach, so I studied how to be able to log in in this case as well.

When you access a URL that requires an HTTP Basic authentication, if you do not provide a user name and password, the server returns 401, and the browser prompts you for a user name and password. Examples are as follows:

The code is as follows Copy Code
if (!isset ($_server[' Php_auth_user ')) {
Header (' Www-authenticate:basic realm= ' My realm ');
Header (' http/1.1 401 Unauthorized ');
} else {
echo "

Hello {$_server[' Php_auth_user '}.

";
echo "

You entered {$_server[' PHP_AUTH_PW '}} as your password.

";
}
?>

Save As login.php, browse http://localhost/login.php to see the effect.


Pop-up authentication dialog box for browser basic AUTH:IE9 and Chrome
Enter the username password in the browser pop-up window, and if you use the Chrome Developer tool (or Firebug), you'll find that it just sends a request header similar to the following:

Authorization:basic bxlfdxnlcm5hbwu6bxlfcgfzc3dvcmq=
Iv. Basic Auth Certified Automatic Login Solution
In principle there are 2 ways to pass Certification

• One is to add Authorization (available Javascript) to the request header:
Authorization: "Basic user name and password base64 encrypted string"
• Add a username and password to the URL (IE not supported):
http://username:password@domain.com/login.php

Add the request header with JS can use XMLHttpRequest, the implementation code is as follows:

The code is as follows Copy Code



Login





Basic Auth Certified Automatic login solution, summarized below--

1, the user name password is directly written in the URL.

Cons: Not secure enough, and IE is not supported.

2, write a login form, PHP to fill in the user name password into the form, and then the page onload JS generated Authorization request header submission

Disadvantage: The system and phpMyAdmin must be in the same domain. For example, the system in the admin.domain.com, and phpMyAdmin in phpmyadmin.domain.com this situation JS is unable to cross-domain submissions.

3, the system will be the user name password post to the PhpMyAdmin domain of a form, that form and then to use JS Landing.

Cons: Need to add a page to the PhpMyAdmin domain to implement the cross-domain.

http://www.bkjia.com/PHPjc/629832.html www.bkjia.com true http://www.bkjia.com/PHPjc/629832.html techarticle This article to introduce the browser basic auth way authentication phpMyAdmin automatic login, there is a need to understand the students can enter the reference. First, demand automatic login phpMyAdmin. Finally able to solve ...

  • 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.