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

  • SEARCH
  • Home
  • 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 8553525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:40:21+00:00 2026-06-11T14:40:21+00:00

Anyone can show me why this piece of code works with the second line

  • 0

Anyone can show me why this piece of code works with the second line but not the first line, although they are the same?

Here is the pass.txt file:

01234567 5f4dcc3b5aa765d61d8327deb882cf99
01234567 5f4dcc3b5aa765d61d8327deb882cf99

Here’s the code:

<?php
    $f = fopen("pass.txt", "r");
    if ($f) {
        $buffer = fgets($f);
        $buffer = fgets($f); //Comment out this line to read the first line

        $token = explode(' ', $buffer);
        if ($token[1] == hash('md5', 'password'))
            echo "Password correct";
        else
            echo "Password incorrect";
    }
?>
  • 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-06-11T14:40:22+00:00Added an answer on June 11, 2026 at 2:40 pm

    As @David Schwartz pointed out, the most possible reason is the newline character.

    You could use file function to ignore the newline char.

    foreach (file('pass.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
        $token = explode(' ', $line);
        if ($token[1] == hash('md5', 'password'))
          echo "Password correct";
        else
          echo "Password incorrect";
    } 
    

    If the file is very large, then use fgets to read it one by one and trim the newline.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to translate this piece of code in VB but I can't figure
I'd like to do this in the INSERT SQL. Can anyone show me. Thanks
Can anyone show a short and simple code snippet? It should take the name
Can anyone give me the example code that I can use to first present
Sorry, but I can only show this problem on a live sandbox site. if
can anyone recommend a website crawler that can show me all of the links
can anyone show me the syntax for inserting a python tuple/list into a mysql
Can anyone show me a way of converting SQL Server data-types (varchar for example)
Can anyone show me how to create a mathematical expression for the number of
Can anyone show me how to make a UIManagedDocument globally accessible?

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.