Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Registration in ajax php

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report