PHP implementation of QR code scan login

Source: Internet
Author: User

I simple implementation of the example, using any QR Code tool to open the QR code corresponding link

Http://www.vincentguo.cn/demo/scan


Principle Introduction:

The first step: Visit the login page, generate a unique key, such as mkhjdfl=, and save this key to the cache with a value of-1, 1 means not logged in

, the key is valid for 5 minutes, it will regenerate the two-dimensional code image


The second step: Generate two-dimensional code, I use the library (https://github.com/2amigos/yii2-qrcode-helper), two-dimensional code corresponding to the link

http://www.vincentguo.cn/demo/qrcode?key=MkhjDFL=


The Third step: login page, JS loop request an interface, I interface Http://www.vincentguo.cn/demo/dologin

Fourth step: Use any app to open the two-dimensional code to drink the link. You should use the app you developed here, and the app is logged in, then use your app to scan the QR code, then the app requests a link to the QR code, so that the key can correspond to the login uid, at this time to modify the cache key corresponding value is the login UID

Fifth step: Since the third step in the duplicate request interface, this interface if the key value in the cache is checked to the UID of the login, it will return the login information and save the login state


PS: The algorithm to generate unique key, you can generate based on time information


Examples are as follows:

I can play: Http://www.vincentguo.cn/demo/scan





Text Address: PHP implementation of QR code scan login

PHP implementation of QR code scan login

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.