I am trying to learn php, and this might be a stupid question, but I've searched my books and the internet and nothing seems to be giving me the answer.
I'm doing a login page. I've written the user information to a txt file and I see that it's delimited with a semi-colon. I can't seem to work around it, so I created a new variable that is made up of the user name and password with the semi-colon inbetween. When I echo the new variable it appears to be the same as the line in the file, but when I compare it in the if statement, if comes up as no match. Here is the code:
<?php
$UserInfo=$_POST["UserName"];
$PasswordInfo=$_POST["Password"];
$VarToTest="$UserInfo:$PasswordInfo";
$fp = fopen ("users.txt", "r");
$check=0;
while (!feof ($fp) && ($check == 0))
{
$content = fgets( $fp, 4096 );
if ($content == $VarToTest)
{
$check = 1;
}
else
{
$check = 0;
}
}
if ($check ==1)
{
echo "Welcome $UserName\n";
echo "<a href='shop.html'>go shopping</a>";
}
else
{
echo "sorry, your information does not match our records\n";
echo "<a href='login.html'>try again</a>";
}
fclose ($fp);
?>
can anyone share some light on this newbie?
many thanks!
Stephanie
I'm doing a login page. I've written the user information to a txt file and I see that it's delimited with a semi-colon. I can't seem to work around it, so I created a new variable that is made up of the user name and password with the semi-colon inbetween. When I echo the new variable it appears to be the same as the line in the file, but when I compare it in the if statement, if comes up as no match. Here is the code:
<?php
$UserInfo=$_POST["UserName"];
$PasswordInfo=$_POST["Password"];
$VarToTest="$UserInfo:$PasswordInfo";
$fp = fopen ("users.txt", "r");
$check=0;
while (!feof ($fp) && ($check == 0))
{
$content = fgets( $fp, 4096 );
if ($content == $VarToTest)
{
$check = 1;
}
else
{
$check = 0;
}
}
if ($check ==1)
{
echo "Welcome $UserName\n";
echo "<a href='shop.html'>go shopping</a>";
}
else
{
echo "sorry, your information does not match our records\n";
echo "<a href='login.html'>try again</a>";
}
fclose ($fp);
?>
can anyone share some light on this newbie?
many thanks!
Stephanie