1A2B.log

  1. After implementing the game 1A2B, try to enhance it by adding records to a log file "1a2b.log" (under the same directory as 1a2b.php).
  2. Each line in the file consists of the following fields, separated by TABs:
    1. Current date and time
    2. How many guesses did it take to guess those 4 digits
    3. How many seconds it took to guess
    4. The remote IP address of the player
    5. The HTTP agent (including OS and the browser) used by the player
  3. You may find it useful to define a function add_record($iteration, $duration).
  4. Current date and time can be obtained by date() in PHP.
  5. The remote IP address may be found from $_SERVER['REMOTE_ADDR'].
  6. The HTTP agent can be identified by $_SERVER['HTTP_USER_AGENT'].
  7. If you encounter a permission issue, and you don't want to open the write permission for the whole directory to anybody, you can try to open only the write permission of a file:
  8. After the record of current play is written to the log file, all the records are shown on the webpage in a table. You may wish to show the last record with a different color to make it distinguishable.
    1A2B Records