Это на самом деле не так уж плохо, если вы знакомы с основами JS / Ajax.
Вам нужно будет вызвать функцию javascript со страницы регистрации.
HTML в регистрационной форме
<!--This is the textbox with the value we are checking-->
<!--onkeyup can be substituted by any other event you wish to use intead-->
<input onkeyup="checkUsername(this.value);" name="username" id="username" />
<!--This is where we'll display the response-->
<div id="response"></div>
Эта функция JS создаст объект ajax, передаст переменную username на страницу PHP для обработки и будет ожидать ответа ...
JavaScript
function checkUsername(username){
//Construct the url, passing the username to the PHP page
var url= 'checkNameAvailability.php?username=' + encodeURIComponent(username);
if (ajax.readyState == 4 || ajax.readyState == 0) {
ajax.open("POST", url, true);
ajax.onreadystatechange = function (){
if (ajax.readyState == 4) {
//When you get the result from the PHP, put it in the response div
document.getElementById('response').innerHTML=ajax.responseText;
}
};
ajax.send(null);
}
}
//Just copy and paste this function - don't change it at all.
function getXmlObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
showError('Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.','Please Wait');
}
}
Затем страница PHP захватывает переменную username, обрабатывает ее любым необходимым способом (доступен ли он, достаточно ли длинен, имеет ли он недопустимые символы, не подходит ли он и т. Д.) И возвращает ответ.
checkNameAvailability.php
<?php
//Accept a variable called 'username' that we are checking.
$username=$_REQUEST['username'];
//Run Checks to see if username is valid
if ($username=="Dutchie")
die ("Username is reserved or already taken");
if (strlen($username)<5)
die("The username is too short.");
die("Username is Valid");
?>