PHP string comparison results in Undefined Offset 3 error
<p>I'm trying to compare a couple of array values stored in a flat file (I know, mysql is much better but its an assigment so please bear with the antiquated methodology) with some form sent user credentials from a $_POST variable and despite there only being one line of data in the file I keep getting the following error:</p>

<p>Notice: Undefined offset: 3 in ./login.php on line 70</p>

<p>I've included the offending lines of code below with some of the preamble and the printed out results from the browser (in a basic attempt at trouble shooting I've run a print_r command and clearly get 2 arrays returned but can't figure out why...?).</p>

<p>If I can add any additional info that would help solve it please let me know - I'll be only too willing to oblige.</p>

<p>The user registration data is captured in this fragment of code from a register.php file</p>

<pre><code>&lt;?php
$filename = '../../private_data/filewriting.php';

if (isset($_POST['register']) &amp;&amp; count($errors)==0) {

    // Submission was OK, so display thank-you message
    $output .= '&lt;p&gt;&lt;strong&gt;Thanks for registering with us! Please click &lt;a href="index.php"&gt;here&lt;/a&gt; to login to the site using your Username and Password&lt;/strong&gt;&lt;/p&gt;';

    $handle = fopen($filename, 'a');

    fwrite($handle, "\n".$clean['fullname']."|".$clean['address']."|".$clean['postcode']."|".$clean['username']."|".$clean['password']);

    fclose($handle);
}
?&gt;
</code></pre>

<p>Then the checking of user input login details happens in this fragment from the login.php file</p>

<pre><code>&lt;?php
$output = '';
$filename = '../../private_data/filewriting.php';

if (isset($_POST['submit']) &amp;&amp; count($errors)==0) {

    $lines = file($filename);

    foreach ($lines as $line) {
        $arr = explode('|', $line);
        print_r($arr);
        echo '&lt;br /&gt;';

        // The next line is the problematic line 70             
        if ($arr[3]==$clean['username'] &amp;&amp; $arr[4]==$clean['password']) {
            $_SESSION['username'] = $clean['username'];
            $_SESSION['password'] = $clean['password'];
            $output .= '&lt;p&gt;&lt;strong&gt;Password and Username match - Thank you for logging in. Please continue to browse the site using the links above.&lt;/strong&gt;&lt;/p&gt;';
        }
    }
}
?&gt;
</code></pre>

<p>The output from this file after submitting the login details is as follows:</p>

<p>Array ( [0] => )</p>

<p>Notice: Undefined offset: 3 in ./login.php on line 70</p>

<p>Array ( [0] => Test User [1] => 123 Shallot Street, The Big Onion [2] => BN21 0LK [3] => testuser [4] => password )</p>

<p>Password and Username match - Thank you for logging in.</p>
