0

I'm trying to create a simple waiting list and display to use a piece of equipment. Users will enter their name using a PHP form, and I can write the name to the end of a text file using something like this:

<?php
$name = $_GET['name'];

$fp = fopen("./name.txt", 'w');
if (!$fp)
{
    echo '<html><body><p>Failed to open file.</body></html>';
    exit;
}

$outputstring = "$name\r\n";
fwrite($fp, $outputstring, strlen($outputstring));

echo "\0";
end;
?>

I was planning to use PHP to read the text file, and pull off the name at the top of the list to display on a web site. However, I'm not sure if it is possible to delete the name once I request it from the text file. I'd also like to clear the text file daily. Are there better alternative ways to create this waiting list? What would you recommend instead?

Alligator
  • 691
  • 3
  • 11
  • 21
  • 3
    I would recommend you on using a database. This comes with a web hosting most of the time and is not that hard to learn for your context. Check your hosting package for one. – Philipp Maurer Nov 27 '17 at 23:42
  • 1
    Yet, if you want to use a file that is not bad too for such a small webapp as yours. I think [this](https://stackoverflow.com/questions/13246597/how-to-read-a-file-line-by-line-in-php) and [this](https://stackoverflow.com/questions/2404707/is-this-the-most-efficient-way-to-get-and-remove-first-line-in-file) might help you. – Philipp Maurer Nov 27 '17 at 23:44
  • You could also store it as an json encoded array. Then you only need to read the file, decode it, work with it as an ordinary array (add/remove/search) and then store it as json again. Storing as file might work if there's only one person working with it at any one time. If there's more than one person working with it, you might run into a bunch of issues (people overwriting each others changes etc). – M. Eriksson Nov 27 '17 at 23:46

0 Answers0