Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>file_get_contents()</code> takes a filename, not a file pointer, so you should use <code>file_get_contents('file.txt')</code> and get rid of the <code>fopen</code> call.</p> <p><a href="http://php.net/manual/en/function.file-get-contents.php" rel="nofollow">http://php.net/manual/en/function.file-get-contents.php</a></p> <p>Then, the value of <code>$file</code> is a string containing all the contents of the file as a single string. So you can use normal string operations and don't need any of that <code>feof</code> stuff.</p> <p>However you may want to look at <code>file()</code>, it is probably useful to you:</p> <p><a href="http://php.net/manual/en/function.file.php" rel="nofollow">http://php.net/manual/en/function.file.php</a></p> <p>EDIT:</p> <p>You also have a problem with your logic.</p> <p>You are checking the username first and then the password as a separate operation. This will match <em>any</em> user with <em>any</em> user's password. Let's say we have users alice with password "foo", and bob with password "bar", well with the current logic, alice will be able to login with either "foo" or "bar" as password.</p> <p>So what you are actually looking for is a single string which is the concatenation of the username and the password, as it is found in the file (e.g. <code>"alice foo".PHP_EOL</code>):</p> <pre><code>if (strpos($file, "$user $password".PHP_EOL) !== false) { // go to login page } else { // error } </code></pre> <p>The reason you need the <code>PHP_EOL</code> in there is that this is what you have used to mark the end of the record. If you don't put it in the search string, then you will match any substring of the real password, including an empty password. (The file contains the text <code>"alice foo".PHP_EOL</code> and it contains the text <code>"alice "</code> but it does not contain the text <code>"alice ".PHP_EOL</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload