Choose your user name
![]() |
Min 6 characters |
This example does not use XML. The server side PHP code checkName.php handles the JavaScript checkName callback by reading a simple text file containing names and returning a string. View this page's source to see the JavaScript.
This script accepts a GET parameter n containing the name to check. This is compared to entries in a text file names.txt. The check could just as easily be against a database. Possible return values are 'tooShort', 'taken' and 'available'.
<?php
header('Content-type: text/plain');
$userName = $_GET['n'];
if ( strlen($userName) < 6 ) exit('tooShort');
$names = file('names.txt');
foreach($names as $v) {
if ( $userName == rtrim($v) ) exit('taken');
}
exit('available');
?>