Results 1 to 14 of 14

Thread: <resloved>check if string is equal to what is in a text file

  1. #1

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Resolved <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?

  2. #2
    Lively Member
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    95

    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($handlefilesize($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.

  3. #3

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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?

  4. #4
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    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?

  5. #5

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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($handlefilesize($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?

  6. #6
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    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 "!"
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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($handlefilesize($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?

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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?

  11. #11
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    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).
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  12. #12

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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?

  13. #13
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    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.
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  14. #14

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    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
  •  



Click Here to Expand Forum to Full Width