<resloved>check if string is equal to what is in a text file
hi, i have made a script that is ment to check if a string is equal to the contents of a text file. here is my code
PHP Code:
<?
$uid = $_POST['uid'];
$pw = $_POST['pw'];
$file = fopen("D:/inetpub/xproot/users/lists/" . $uid . 'pw.txt','r');
if (fpassthru($file) == $pw)
{
//DO CODE FOR SUCCESSFULL LOGIN
} else {
//DO CODE FOR UNSUCCESSFULL LOGIN
}
?>
i have not yet finnished my code but for some reason it echos the password which is not what i want it to do. i would like it to check if $pw is equal to the content of the text file. I think i may have the wrong function.
Re: check if string is equal to what is in a text file
Try This:
PHP Code:
<?php
$uid = $_POST['uid'];
$pw = $_POST['pw'];
$file = "D:/inetpub/xproot/users/lists/" . $uid . "pw.txt";
$handle = fopen($file,'r');
$pass = fread($handle, filesize($file));
$pass = trim($pass);
//Check to see if contents of file equals the $pw variable
if ($pass == $pw)
{
//DO CODE FOR SUCCESSFULL LOGIN
} else {
//DO CODE FOR UNSUCCESSFULL LOGIN
}
?>
Re: check if string is equal to what is in a text file
it returned this:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in D:\Inetpub\XPROOT\Login\login.php on line 14
what is wrong? it is something to do with the if and else statements but i dont see what is wrong with it.
Re: check if string is equal to what is in a text file
Looks good to me, what code are using inside your 'if' loop?
Re: check if string is equal to what is in a text file
it is just me testing it at the moment. it happened on the code that RyanElliss posted
PHP Code:
<?php
$uid = $_POST['uid'];
$pw = $_POST['pw'];
$file = "D:/inetpub/xproot/users/lists/" . $uid . "pw.txt";
$handle = fopen($file,'r');
$pass = fread($handle, filesize($file));
$pass = trim($pass);
//Check to see if contents of file equals the $pw variable
if ($pass == $pw)
{
echo "Success!"
} else {
echo "Unsuccessfull!"
}
?>
it echos the word success on a successfull login and unsuccessfull on unsucessfull login. prety strait forward
Re: check if string is equal to what is in a text file
ummm... you are forgetting the number one rule for CGI & PHP, always look to see if you put a ";" at the end of a statment! also, i am not sure about php, but you may want to put "\!" insted of just a "!"
Re: check if string is equal to what is in a text file
ALL is right, it is basic syntax, you must include a terminating semi colon at the end of every statement.
P.s: the only character which must be escaped in a PHP string is a backslash (\) because it is th3e escape character. :)
Re: check if string is equal to what is in a text file
fixed it. thanks.
PHP Code:
<?php
$uid = $_POST['uid'];
$pw = $_POST['pw'];
$file = "D:/inetpub/xproot/users/lists/" . $uid . "pw.txt";
$handle = fopen($file,'r');
$pass = fread($handle, filesize($file));
$pass = trim($pass);
//Check to see if contents of file equals the $pw variable
if ($pass == $pw)
{
echo "Success!";
} else {
echo "Unsuccessfull!";
}
?>
why do most websites that use text logins use only one text doc. with one text doc per user you can do many more things like change password and remove the user.
Re: check if string is equal to what is in a text file
Quote:
Originally Posted by dandono
why do most websites that use text logins use only one text doc. with one text doc per user you can do many more things like change password and remove the user.
By the time you get to that point, it is a lot easier to use a database.
Re: check if string is equal to what is in a text file
my server does not like databases much. MySQL does not get on with it. It is installed but does not work so i just went with text.
thanks, dandono
Re: <resloved>check if string is equal to what is in a text file
ya, the two servers i use dont like to use MySQL either, because it hoggs CPU usage. so my forums are all files (which those directories are blocked to normal users).
Re: <resloved>check if string is equal to what is in a text file
just give the files names that no body would guess but have a place in each file name that the username is in like "blahblahblahdandonoblahlalala.txt" nobody would even know that the filename had a "b" in it
Re: <resloved>check if string is equal to what is in a text file
why, when you can just set the access in the ".htaccess" file. i cant remember exactly what to put, but in the directory, put a file named ".htaccess" and in the file put: "deny from all" and that will not allow anyone to access any files in that directory. but i believe that is one of those Apache things.
Re: <resloved>check if string is equal to what is in a text file
why, because you own the server and you have the actual mechene then why not just have the files write and read from a file in a directory that is not in yor website folder. if i thought for a while i could probably make up a user rights system for the text login thing so that users with administrator priviliges can view and change anything. a bit like vbforums user system does but wite loads of text docs insted of a database.