INQ177CJ
Computational Aspects of E‑commerce

Activity 10

PHP Functions

Elapsed Time

Create a new php web page that logs the date and time whenever a user views the page. To do this:

  1. Create a new text file called ‘log.txt’ and change the permissions of the file so that the server can write to the file.

  2. Use the fopen function to open a file called ‘log.txt’. Because you want write to the file without overwriting what is already in the file, it needs to be opend in append mode. Do this by using ‘a’ for the mode input argument.

  3. Use the fwrite function to write the text ‘page accessed’ to the file ‘log.txt’. Because you want write to the file without overwriting what is already in the file, it needs to be opend in append mode. Do this by using ‘a’ for the mode input argument of the fopen function.

    Test the code by loading the php web page in the web browser and then opening the file ‘log.txt’ to verify that it contains the text ‘page accessed’. Reload the page a couple of times and verify that the file ‘log.txt’ contains the text ‘page accessed’ multiple times.

  4. Use the time function to add the current time to each entry in the log. Note the time function stores returns the current time as a single integer so your log entries should look something like this: page acccessed at: 1432303118729.

  5. Use the date function to make the time in the log easier to read. It should look something like: May 22, 2015, 9:58 am.

Submission

Please show your completed web page and source code to the instructor.