Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Registration in ajax php

Shulou Source: shulou.com Published: 2022-06-02 04:08:58 09月24日 Update

Ajax php how to achieve registration, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Ajax php registration method: 1, create login.html registration login page; 2, through jquery code verification; 3, use PHP code userLogin.php and addUser.php to achieve user login and registration function.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

How does ajax php register?

JQuery+ajax+php realizes the function of registration and login

Html code, login.html

Username and password verification code

Login and registration

Jquery code, login.js

$('img') .click (function () {$(' img'). Attr ('src','php/getVerify.php?'+Math.random ()); / / Refresh CAPTCHA}) $(' # login') .click (function () {var username=$ ('# user-name') .val (); var password=$ ("# user-password") .val () Var code=$ ("# code") .val () If (username = "" & passwordkeeper = "" & & code.length==4) {$.ajax ({type: "POST", url: "php/userLogin.php", dataType: "JSON" Data: {"user_name": username, "password": password, "code": code} Success:function (data) {switch (data) {case 1 data / regular user $.cookie ("user", username) $.cookie ("limit", 0); _ window.location.href= "index.php"; break Case 2 username / administrator user $.cookie ("user", cookie); $.cookie ("limit", 1) _ window.location.href= "index.php"; break Case 3Rank / wrong password alert ("wrong password!") ; break; case 4 / user does not exist alert ("this user does not exist!") ; break; case 0Plus / CAPTCHA error alert ("CAPTCHA is incorrect!") ; break })} else {alert ("Please check your input!") ;}}) $('# sign') .click (function () {var username=$ ('# user-name'). Val (); var password=$ ("# user-password"). Val (); var code=$ ("# code"). Val () If (username = "" & passwordkeeper = "" & & code.length==4) {$.ajax ({type: "POST", url: "php/addUser.php", dataType: "JSON" Data: {"user_name": username, "password": password, "code": code} Success:function (data) {switch (data) {case 1 data / user already exists alert ("this user already exists! Please register with a different user name. ") Break; case 2 hand / successfully registered alert ("registered successfully!") ; $.cookie ("user", username); $.cookie ("limit", 0); _ window.location.href= "index.php" Break; case 0VANTCHA / CAPTCHA error alert ("CAPTCHA is incorrect!") ; break })} else {alert ("Please check your input!") ;})

Php code, userLogin.php

Tags: User authentication error code password login success normal function user name administrator help check manage input clear content for this article novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Shulou Technology MariaDB vpn