help with string comparing.
Posted: Fri Aug 14, 2009 4:02 pm
// use when the password and userid is not correct.
function userIDPasswordAdmin($userid, $password)
{
echo 'Your UserID "' . $userid .'" or Password: "'.$password.'"is not correct. Please try again.';
admin();
}
// print the admin form .
function admin()
{
echo '<form action="admin.php" method="post">
UserID:<input type = "text" name = "userid"/> <br/>
Password:<input type = "password" name = "password" /><br/>
<input type = "submit" />
</form>';
}
// check if the userid and password is correct.
function accept($userid, $password)
{
echo $userid ." accept function " . $password;
//open file
$f_handel = fopen("Utility/Documents/Admin.txt", "rb") or die ("Can not open the admin file.");
while (!feof($f_handel))
{
$UserID = str_replace("\n", '',(fgets($f_handel, 16)));
$PassWord = str_replace("\n", '',(fgets($f_handel, 16)));
echo $UserID ." read file data " . $PassWord;
if ($UserID == $userid && $PassWord == $password)
{
fclose($f_handel);
echo "<br>return true";
return true;
}
}
fclose($f_handel);
echo "<br>return false";
return false;
}
<?php
if (($_POST["userid"] == "") || ($_POST["password"] == ""))
{
echo "admin is called.";
admin();
}
elseif ($_POST["edit"] == true || (accept($_POST["userid"], $_POST["password"])))
{
echo "update is called.";
if ($_POST["update"] == "true")
{ update($_POST); }
edit( $_POST);
}
else
{
echo $_POST["userid"];
echo '$_POST["userid"]'.'haha';
userIDPasswordAdmin($_POST["userid"], $_POST["password"]);
}
?>
http://shiqiangchen.com/Mobile/admin.php
I don't know why when the two string is same but it return false.
function userIDPasswordAdmin($userid, $password)
{
echo 'Your UserID "' . $userid .'" or Password: "'.$password.'"is not correct. Please try again.';
admin();
}
// print the admin form .
function admin()
{
echo '<form action="admin.php" method="post">
UserID:<input type = "text" name = "userid"/> <br/>
Password:<input type = "password" name = "password" /><br/>
<input type = "submit" />
</form>';
}
// check if the userid and password is correct.
function accept($userid, $password)
{
echo $userid ." accept function " . $password;
//open file
$f_handel = fopen("Utility/Documents/Admin.txt", "rb") or die ("Can not open the admin file.");
while (!feof($f_handel))
{
$UserID = str_replace("\n", '',(fgets($f_handel, 16)));
$PassWord = str_replace("\n", '',(fgets($f_handel, 16)));
echo $UserID ." read file data " . $PassWord;
if ($UserID == $userid && $PassWord == $password)
{
fclose($f_handel);
echo "<br>return true";
return true;
}
}
fclose($f_handel);
echo "<br>return false";
return false;
}
<?php
if (($_POST["userid"] == "") || ($_POST["password"] == ""))
{
echo "admin is called.";
admin();
}
elseif ($_POST["edit"] == true || (accept($_POST["userid"], $_POST["password"])))
{
echo "update is called.";
if ($_POST["update"] == "true")
{ update($_POST); }
edit( $_POST);
}
else
{
echo $_POST["userid"];
echo '$_POST["userid"]'.'haha';
userIDPasswordAdmin($_POST["userid"], $_POST["password"]);
}
?>
http://shiqiangchen.com/Mobile/admin.php
I don't know why when the two string is same but it return false.