How can PHP scripts differentiate between different entries in a guestbook file?

To differentiate between different entries in a guestbook file, PHP scripts can use a unique identifier for each entry, such as a timestamp or an auto-incrementing ID. This identifier can be stored alongside the guestbook entries in the file and used to distinguish between them when displaying or processing the entries.

// Sample code to differentiate between guestbook entries using timestamps as unique identifiers

$guestbookFile = 'guestbook.txt';
$entries = file($guestbookFile, FILE_IGNORE_NEW_LINES);

foreach ($entries as $entry) {
    list($timestamp, $name, $message) = explode('|', $entry);
    
    echo "Entry from $name on " . date('Y-m-d H:i:s', $timestamp) . ": $message<br>";
}