|
-
May 12th, 2005, 10:18 AM
#1
Thread Starter
Hyperactive Member
<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.
Last edited by dandono; May 14th, 2005 at 03:31 AM.
If there is only one perfect person in the universe, does that make them imperfect?
-
May 12th, 2005, 11:19 AM
#2
Lively Member
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
}
?>
Last edited by RyanEllis; May 12th, 2005 at 11:26 AM.
-
May 13th, 2005, 03:07 AM
#3
Thread Starter
Hyperactive Member
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.
If there is only one perfect person in the universe, does that make them imperfect?
-
May 13th, 2005, 04:57 AM
#4
Addicted Member
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?
-
May 13th, 2005, 11:46 AM
#5
Thread Starter
Hyperactive Member
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
If there is only one perfect person in the universe, does that make them imperfect?
-
May 13th, 2005, 05:21 PM
#6
Fanatic Member
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 "!"
-
May 13th, 2005, 05:33 PM
#7
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.
-
May 14th, 2005, 03:21 AM
#8
Thread Starter
Hyperactive Member
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.
If there is only one perfect person in the universe, does that make them imperfect?
-
May 14th, 2005, 03:23 AM
#9
Re: check if string is equal to what is in a text file
 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.
-
May 14th, 2005, 03:31 AM
#10
Thread Starter
Hyperactive Member
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
If there is only one perfect person in the universe, does that make them imperfect?
-
May 14th, 2005, 10:34 AM
#11
Fanatic Member
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).
-
May 14th, 2005, 10:56 AM
#12
Thread Starter
Hyperactive Member
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
If there is only one perfect person in the universe, does that make them imperfect?
-
May 14th, 2005, 11:31 AM
#13
Fanatic Member
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.
-
May 14th, 2005, 01:02 PM
#14
Thread Starter
Hyperactive Member
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.
If there is only one perfect person in the universe, does that make them imperfect?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|