Andy Fang Posted August 19, 2013 Share Posted August 19, 2013 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 More sharing options...
Antonio Conte Posted August 19, 2013 Share Posted August 19, 2013 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 More sharing options...
Andy Fang Posted August 19, 2013 Author Share Posted August 19, 2013 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 More sharing options...
HartleySan Posted August 19, 2013 Share Posted August 19, 2013 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? 1 Link to comment Share on other sites More sharing options...
Recommended Posts