Jump to content
Larry Ullman's Book Forums

Get List Of Accounts From .Txt File?


Recommended Posts

I basically have a .txt file kind of like this:

 

username:password

username1:password1

username2:password2

 

I want to make it so that everytime a button is clicked, one username and password will be emailed from the file.

 

How do I do this?

Link to comment
Share on other sites

1. Open the file using fopen() (Check for a GET request from the form you have a button in)

2. Read through the file and assign it to an array

3. Pop the last (or first, but that'll be slower) element from the array

4. Use the email() function to send it where it should

5. Write the array back to the file

6. Close the file

 

Search for how to handle these problems, and you should be able to make it work quite quickly.

Link to comment
Share on other sites

1. Open the file using fopen() (Check for a GET request from the form you have a button in)

2. Read through the file and assign it to an array

3. Pop the last (or first, but that'll be slower) element from the array

4. Use the email() function to send it where it should

5. Write the array back to the file

6. Close the file

 

Search for how to handle these problems, and you should be able to make it work quite quickly.

 

The problem is I don't know how to automatically assign the username:password an array and mail them in a rotating order (first time is the first line, second time mails second line, etc.

Link to comment
Share on other sites

Here's the basic flow:

 

<?php
  
  $txt_data = file_get_contents('path-to-text-file.txt'); // Will get all the text in the entire file as a single string.
  
  $lines = explode(PHP_EOL, $txt_data); // PHP_EOL is a constant in PHP that will get the proper end-of-line character for you.
  
  $top_line_data = explode(':', array_shift($lines)); // Get the first entry in the array and split it. Note that the array stays modified.
  
  $user_name = $top_line_data[0];
  
  $password = $top_line_data[1];
  
  // Code for sending the email goes here.
  
  file_put_contents('path-to-text-file.txt', implode(PHP_EOL, $lines)); // Put the string back into the file sans the first line.

Does that make sense?

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...