Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5998081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:21:17+00:00 2026-05-23T00:21:17+00:00

I am currently writing a php script that validates a username and password. I

  • 0

I am currently writing a php script that validates a username and password. I am working by testing things little by little and right now I have a password file with only one line in it:

user:0011

I am using preg_split to parse the lines in this file and have the following code in my php script:

<html>
<body>

<?php 

    ini_set('display_errors',1);
    error_reporting(E_ALL);

    $usr = $_POST['username'];
    $pass = $_POST["pword"];


    $f = fopen('passwords.txt','r');
    $auth = false;

    while(!feof($f))
    {
        $login = preg_split("/:/",fgets($f));
        echo $login[0]."<br/>";
        echo $login[1]."<br/>";
        print_r($login);
        if($usr == $login[0] && $pass == $login[1])
        {
            echo "in if<br/>";
            $auth = true;
            break;
        }
    }

    if($auth)
        echo "success";
    else
        echo "fail!";

    /*$test = preg_split("/:/","me:you");
    echo $test[0];*/


    fclose($f);
?>

</body>
</html>

The problem is that this is the output it give me is:

user
0011
Array ( [0] => user [1] => 0011 )
Notice: Undefined offset: 1 in /srv/www/htdocs/PHP/val.php on line 20
Array ( [0] => ) fail!

This error doesn’t make sense to me because it is implying that the array is not long enough to have a value at index 1, but I just printed that value and even in the result from print_r it shows there being a value at that index. Does anyone have any idea what is causing this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:21:18+00:00Added an answer on May 23, 2026 at 12:21 am

    You’re on the second iteration of the while loop is my guess; try throwing in a simple counter to check. If you have a newline in the file that would do it.

    try doing this at the top:

    $lrec = trim(fgets($f));
    if (empty($lrec)) {
        continue;
    }
    $login = preg_split("/:/",$lrec);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a PHP script that 3rd party clients will be able to
I am currently writing a little bootstrap code for a service that can be
I have a PHP script that will generate a report using PHPExcel from data
I am currently writing a script that will basically ‘install’ a codeigniter installation automatically.
I'm writing a (PHP) script that serves files to the client. Among others, the
Our company is currently writing a GUI automation testing tool for compact framework applications.
I am currently writing a simple, timer-based mini app in C# that performs an
I'm currently writing a simple .sh script to parse an Exim log file for
I'm re-writing a website that will support multiple skins. Currently, I'm just planning on
So I have found a number of tutorials/guides for running a php script as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.