Forum Moderators: coopster
$getuser = fgets($file);
if ($getuser==$_POST["username"]) {
echo "YES!";
} else {
echo "NOO!";
}
the problem i think is coming from the username that im drawing from a text file, for some reason it doesnt think it the same even though when you echo $getuser, its exactly the same.
can anyone help?
i tested your code. this is the test code i used. i had to add some missing code, which i assume u have in your source. it is working for me. if u still have the same problem, could u post a larger piece of ur code?
<?php
$file = fopen('test.txt', 'r');
$getuser = fgets($file);
if ($getuser==$_GET["username"]) {
echo "YES!";
}
else {
echo "NOO!";
}
?>
echo $username;
if (!$file=fopen($filename, 'r')) {
echo "file could not be opened";
exit;
} else {
while (!feof($file)) {
$getuser = fgets($file);
$getpass = fgets($file);
if ($getuser==$username) {
echo "YES!";
exit;
} else {
echo "NOO!";}
}
}
fclose($file);
?>
this is all of it.. are $_GET and $_POST different? $_GET doesnt seem to return the value properly.
If after echoing the values, you find they are equal, the next thing I'd do is trim() both values while comparing. This removes whitespace from both ends of each variable (that includes "\n", "\r", and spaces.
I'm guessing though that either $getuser or $_POST['username'] is not set to the value you think it is.
i then read the file, one char at a time until i got to the end char adding each one to a seperate variable and then authenticating the whole variable, it works great.. took me back to the days of BBC basic file handling where you had no line breaks at all!
madness, thx for all your help everyone, if anyone wants to see how i got round it, even if i think it is the hardway, id be happy to show you.