By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,635 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,635 IT Pros & Developers. It's quick & easy.

Php signup problem

P: n/a
jon
Hey, i've been trying to create a signup page that asks for a
username, password and then to confirm the password. It is suppose to
check how long both of them are, and if the passwords line up, that
went well, but i can't make it check to see if it is being used by
someone else. heres the script, good luck.

/
*************************signup.html************** ************************************************** ***/
<fieldset>
<form method="POST"action="signup.php">
Username: <input type="text"name="user"/><br/>
Password: <input type="password"name="passa"/><br/>
Confirm password: <input type="password"name="passb"/><br/>
<input type="submit"value="Submit"/>
</form>
</fieldset>
/
************************************************** ************************************************** ****/
/
****************signup.php************************ ************************************************** ***/
<?php
/********Get info********/
$user = $_POST["user"];
$pass_a = $_POST["passa"];
$pass_b = $_POST["passb"];
/*************************^^^^^^^^^^^************** ***********/
/******Key varibles******/
$flag = "OK";
$msg = "";
$num = "0";
/*************************^^^^^^^^^^^************** ***********/
/********Validate Form***/
if(strlen($user) <6)
{
$msg=$msg."(Please enter username that is more then 6 characters in
length)<br/>";
$flag="NOTOK";
}

if(strlen($pass_a) < 6)
{
$msg=$msg."(Please enter password that is more then 6 characters in
length)<br/>";
$flag="NOTOK";
}

if($pass_a != $pass_b)
{
$msg=$msg."(Your passwords don't line up)<br/>";
$flag="NOTOK";
}

/*********check for username********/

$file_a = fopen("user.txt", "r");

$i = 0;
while(!feof($file_a))
{
$userA[$i] = fgets($file_a);
$i++;
}

for($n=0; $n<$i; $n++)
{
$num = $num + substr_count($userA[$n], $user);
}
fclose($file_a);

if($num >= 1)
{
$flag = "NOTOK";
$msg=$msg."(Your username has already been taken)<br/>";
}
/*************************^^^^^^^^^^^************** ***********/
if($flag != "OK")
{
echo "<center>$msg <br<input type='button' value='Retry'
onClick='history.go(-1)'></center>";
}

else
{
$file_a = fopen("user.txt", "a");
$file_b = fopen("pass.txt", "a");

fwrite($file_a, "\n,\"$user\"");
fwrite($file_b, "\n,\"$pass_a\");
echo "congrates you have now signed into the secret page<br/>";
fclose($file_a);
fclose($file_b);
}

?>
/
************************************************** ************************************************** ******/
/***************************User.txt************not
real********************************************** *****/
"blah"
"blank"
"blog"
"bloogg"
/
************************************************** ************************************************** *******/

Feb 2 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.