AJAX user registration demo program_PHP tutorial
User registration demo program
<! doctype html public "-//w3c//dtd html 4.0//en" "http://www.w3.org/tr/rec-html140/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title>ajax用户注册演示程序</title> <script language="网页特效" type="text/网页特效"> <!-- //创建函数 function createxmlhttp() { var request; var browser = navigator.appname; //使用ie,则使用xmlhttp对象 if(browser == "microsoft internet explorer") { var arrversions = ["microsoft.xmlhttp", "msxml2.xmlhttp.4.0", "msxml2.xmlhttp.3.0", "msxml2.xmlhttp","msxml2.xmlhttp.5.0"]; for (var i=0; i < arrversions.length; i++) { try { //从中找到一个支持的版本并建立xmlhttp对象 request = new activexobject(arrversions[i]); return request; } catch (exception) { //忽略,继续 } } } else { //否则返回一个xmlhttprequest对象 request = new xmlhttprequest(); if(request.overridemimetype) { request.overridemimetype('text/xml'); } return request; } } //全局xmlhttp对象实例变量 var http = createxmlhttp(); //发送请求 function chkuser() { var url = "check.php教程"; //请求"checkusername" servlet var name = document.getelementbyid("username").value; url += ("?username="+escape(name)+"&oprate=chkuser"); http.open("get",url,true); http.onreadystatechange = processhttpresponse; http.send(null); return ; } //处理响应 function processhttpresponse() { if(http.readystate == 4) { if(http.status == 200) { var xmldocument = http.responsexml; if(http.responsetext!="该用户名有效,可以使用!") { //返回的信息动态显示 document.getelementbyid("showstr").style.display = ""; document.getelementbyid("username").style.background= "#ff0000"; document.getelementbyid("showstr").innertext = http.responsetext; } else { document.getelementbyid("username").style.background= "#ffffff"; document.getelementbyid("showstr").style.display = ""; document.getelementbyid("showstr").innertext = http.responsetext; } } else { alert("你所请求的页面发生异常,可能会影响你浏览该页的信息!"); alert(http.status); } } } //检验输入密码 function chkpassword() { var m=document.form1; if(m.password.value.length>20 || m.password.value.length<6 ) { document.getelementbyid("passwordstr").style.display = ""; document.getelementbyid("password").style.background= "#ff0000"; document.getelementbyid("passwordstr").innertext = "对不起,密码必须为英文字母、数字或下划线,长度为6~20!"; } else { document.getelementbyid("password").style.background= "#ffffff"; document.getelementbyid("passwordstr").style.display = "none"; } } //验证两次密码是否一致 function chkconfirmpassword() { var m=document.form1; if (m.password.value != m.confirmpassword.value) { document.getelementbyid("confirmpasswordstr").style.display = ""; document.getelementbyid("confirmpassword").style.background= "#ff0000"; document.getelementbyid("confirmpasswordstr").innertext = "对不起,密码与重复密码不一致!"; } else { document.getelementbyid("confirmpassword").style.background= "#ffffff"; document.getelementbyid("confirmpasswordstr").style.display = "none"; } } //验证email是否有效 function chkemail() { var m=document.form1; var email = m.email.value; //正则表达式 var regex = /^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+/; var flag = regex.test(email); if(!flag) { document.getelementbyid("emailstr").style.display = ""; document.getelementbyid("email").style.background= "#ff0000"; document.getelementbyid("emailstr").innertext = "对不起,邮箱地址无效!"; } else { document.getelementbyid("email").style.background= "#ffffff"; document.getelementbyid("emailstr").style.display = "none"; } } //提交检查函数 function submitcheck() { var m=document.form1; if(m.username.value.length==0) { alert("对不起,用户名必须为英文字母、数字或下划线,长度为5~20。"); m.username.focus(); return false; } if(m.password.value.length==0) { alert("对不起,密码必须为英文字母、数字或下划线,长度为5~20。"); m.password.focus(); return false; } if (m.password.value != m.confirmpassword.value) { alert("对不起,密码与重复密码不一致!"); m.confirmpassword.focus(); return false; } if(m.email.value.length==0) { alert("对不起,邮箱地址不能为空!!"); m.email.focus(); return false; } m.submit(); } //--> </script> <body > <form name="form1" method="post" action="register.php"> <h3 id="ajax用户注册程序">ajax用户注册程序</h3> <table align="center" width="500" border="1" > <tr> <td><font color="red">*</font></td> <td width="100">用户帐号:</td> <td><input type="text" name="username" maxlength="20" style="background=#ffffff" onblur="chkuser()"></td> <td><div id="showstr" style="background-color:#ff9900;display:none"></div></td> </tr> <tr> <td><font color="red">*</font></td> <td>用户密码:</td> <td align="left"><input type="password" name="password" maxlength="22" style="background=#ffffff" onblur="chkpassword()"/> </td> <td><div id="passwordstr" style="background-color:#ff9900;display:none"></div></td> </tr> <tr> <td><font color="red">*</font></td> <td>确认密码:</td> <td><input type="password" name="confirmpassword" maxlength="20" style="background=#ffffff" onblur="chkconfirmpassword()"/></td> <td><div id="confirmpasswordstr" style="background-color:#ff9900;display:none"></div></td> </tr> <tr> <td><font color="red">*</font></td> <td>email:</td> <td><input type="text" name="email" maxlength="100" style="background=#ffffff" onblur="chkemail()"></td> <td><div id="emailstr" style="background-color:#ff9900;display:none"></div></td> </tr> </table> <div align="center"> <input type="button" name="ok" value=" 确定 " onclick="submitcheck()"> <input type="reset" name="reset" value=" 取消 "> </form> </div> </body> </html>reg.php检测程序 <?php header("content-type:text/html;charset=gb2312"); @mysql教程_connect('localhost','root','ebaeba') or die("数据库教程服务器连接失败"); @mysql_select_db("test") or die("数据库不存在或不可用"); $uname = $_get['username']; //下面进行数据库查询 查找是不是有这一个用户 //如果没有查找到这个用户名 $sql="select * from t1 where name='".$uname."'"; $query=mysql_query($sql); $row=mysql_fetch_object($query); if(strlen($uname)<6||strlen($uname)>20) { $msg="用户名必须是6至20个字符."; } else { if($row==false) { $msg="该用户名有效,可以使用!"; } else { $msg="对不起,此用户名已经存在,请更换用户名注册!"; } } echo $msg ; ?>

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1
Easy-to-use and free code editor
