i made a registration page for my application by using flat file database. I was wondering if it is possible using flat file database to make so whoever is registering cannot use the same name that is already registered, if so how?
Below is my register page:
<div align="center">
<?PHP
if (isset($_POST['submit']))
{
$username = $_POST["username"];
$password = $_POST["password"];
$password1 = $_POST["password1"];
if(empty($username)) die(print '<script> alert ("Enter Username"); window.location="registration.php"; </script>');
if(empty($password)) die(print '<script> alert ("Enter Password"); window.location="registration.php"; </script>');
if($password != $password1) die(print '<script> alert ("Password doesn\'t match"); window.location="registration.php"; </script>');
require_once('recaptchalib.php'); // reCAPTCHA Library
$privkey = "xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // Private API Key
$verify = recaptcha_check_answer($privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if ($verify->is_valid) {
$file = file_get_contents("data.txt");
$string = "$username||$password";
if(!strstr($file, "$string"))
{
$myFile = "data.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "$username||$password
";
fwrite($fh, $stringData);
print '<script> alert ("Registration Complete"); window.location="/~u1206424/index.php"; </script>';
fclose($fh);
}
else
{
die(print '<script> alert ("Sorry the username: <b>$username</b> is already registered. Please use diferent username"); window.location="registration.php"; </script>');
}
}
else {
die(print '<script> alert ("You did not enter the correct Captcha. Please try again"); window.location="registration.php"; </script>');
}
}
?>
</div>
<!doctype html>
<html>
<head>
<title>Registration</title>
</head>
<body>
<div id="container" style="width:500px; height:500px; border: 2px solid black; margin:auto">
<?php include "header.php"; ?>
<div id="content" style="background-color:#EEEEEE; width:500px; height:400px; float: left">
<br>
<form align="center" method="post" action="registration.php" >
Username:
<input type="text" name="username" />
<br/>
<br/>
Password:
<input type="password" name="password" />
<br/>
<br/>
Confirm:
<input type="password" name="password1" />
<br/>
<br/>
<?php
require_once('recaptchalib.php'); // reCAPTCHA Library
$pubkey = "6Lcx-esSAAAAAIps5xUbcy7ty45P1usxQWheLpXO"; // Public API Key
echo recaptcha_get_html($pubkey); // Display reCAPTCHA
?>
<input type="submit" value="Register" name="submit" />
</form>
</div>
<?php include "footer.php"; ?>
</div>
</body>
</html>