


Code for php+ajax to dynamically verify whether the username has been registered
本文介绍下,php与ajax结合,实现验证用户名是否已注册的代码,有需要的朋友,可以参考下。
1,用户注册页 Login.html <html> <head> <title>用户注册_bbs.it-home.org</title> <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { //在IE下创建XMLHttpRequest对象 try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc) { xmlHttp = null; } } //在Mozilla和Safari等非IE浏览器下创建XMLHTTPRequest对象 if(!xmlHttp && typeof XMLHttpRequest != "undefined") { xmlHttp = new XMLHttpRequest(); } return xmlHttp; } //方式请求 function startRequest() { //获取用户输入的信息 var UserID = document.getElementById("UserID").value; //输入的用户名是否为空 if(UserID!="") { //创建XMLHttpRequest对象 createXMLHttpRequest(); var url = "Login.php?UserID="+encodeURI(UserID); //指定url xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange = handleStateChange; //指定回调函数 xmlHttp.send(null); } else { alert("请填写您的用户名!"); } } function handleStateChange() { if(xmlHttp.readyState<4) { span.innerHTML="正在读取数据..."; } if(xmlHttp.readyState==4) { if(xmlHttp.status == 200) { span.innerHTML=xmlHttp.responseText; } else{ alert("错误,请求页面异常!"); } } } </script> </head> <body> <form action="#"> <center> <h3 id="Ajax-php验证用户名是否可用">Ajax+php验证用户名是否可用</h3> <table> <tr> <td>用户名: <input type="text" name="UserID" id="UserID" onchange="startRequest()" /> <span id="span"></span></td> </tr> <tr> <td>密 码: <input type="text" name="Pwd" id="Pwd"/></td> </tr> <tr> <td> <br/> <input type="button" name="Reg" id="Reg" value="注册"/> <input type="button" name="Log" id="Log" value="登录"/> </td> </tr> </table> </center> <form> </body> </html> Copy after login 2,注册检测页 Login.php <?php //设置PHP的显示语言 header('Content-Type:text/html;charset=UTF-8'); //让程序先等待一秒 sleep(1); //获取输入的用户名 $tmp=$_GET["UserID"]; $db_host="localhost"; $db_name="canphp"; $db_username="root"; $db_password="rootpass"; $link = mysql_connect($db_host, $db_username,$db_password ) or die ('Can\'t connet db!' . mysql_error()); mysql_select_db($db_name, $link) or die ('Can\'t select db : ' . mysql_error()); $query="select * from cp_user where username='$tmp'"; $result = mysql_query($query) or die ($query.mysql_error()); $rows=mysql_num_rows($result); if($rows>0) { //存在记录 echo "用户名已存在"; }else{ echo("可以注册!"); } ?> Copy after login |

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
