To realize the two-dimensional code login, need to solve 2 technology, 1, the need for JS WebSocket and background PHP to achieve long-connection technology
2, realize the two-dimensional code generation technology
To achieve this function the second is relatively simple, only need to download a PHP two-dimensional code generator can be, but to achieve long-connection technology, through the multi-check data, there are 2 ways 1 is nodejs to achieve back-end services, the other is to use a PHP extension swool to achieve background services, This example uses the latter swool,
The first step, when you open the login page, using PHP to generate a unique sign, using JS WebSocket technology to connect to the background service, and sign to the background service, while using sign to generate two-dimensional code
The second step, backstage service after receiving this sign, the sign and the store socket client side of the third step, the use of the app-side QR Code tool to scan the QR code, the activity of a string generated by signs, and the string and the current login user information, through the interface call passed to the background
Fourth step, the server interface received the information, the sign and user information to do the check, check error, after sending the socket message to the background service, the background service received a message to find the corresponding client, and send a message to the client, confirm the login
Fifth Step, Login page received confirmation of login message, upload to sign to login page
The sixth step, the PHP login page after receiving sign, verify signs, OK login
Today's website background login page needs to generate a QR code, and then scan the QR code on the mobile app to achieve the website login effect and the following solutions