Create a php file that outputs "You are visitor: $n" (where $n is the number of page hits) using the following functions:
file_existsfile_get_contentsfile_put_contentsecho
Only add to the page hit counter if this IP address has never been seen before. Record the seen IP's in a separate data file.
in_arrayserializeandunserialize(easier), orpack,unpackandip2long(more challenging)
view-comments.php: Outputs the comments stored in a data file, along with a form to post new comments. Displays a friendly message if no comments.post-comment.php: Appends a new comment to the data file, and redirects toview-comments.phpif successful. Displays a friendly error message if thecommentparameter is missing.
emptyhtmlspecialcharsfile_existsfile_get_contentsfile_put_contentsserializeunserializeheader
Instead of using a hard-coded data file name to store the comments, implement the following interface in a class to manipulate $articleID.dat
<?php
interface ArticleCommentInterface {
public function __construct($articleID);
public function getComments();
public function addComment($comment);
}- [Filesystem Security] FILE_SEC
- [Classes and Objects: The Basics] CLASS_BASICS
- [Classes and Objects: Properties] CLASS_PROPERTIES
- [Classes and Objects: Constructors and Deconstructs] CLASS_CONSTRUCTORS
- [Classes and Objects: Object Interfaces] CLASS_INTERFACES
Repeat lessons 1 and 2, but with MySQL database server to replace the data files. Should display the error message from DB server on connection or query error. For extra fun, use the object-oriented mysqli interface.
- [Database Security: SQL Injection] SQL_INJECTION
- [MySQLi: Dual procedural and object-oriented interface] 5
- [3.3 Creating and Using a Database] 6
mysqli_connectmysqli_connect_errnomysqli_connect_errormysqli_querymysqli_real_escape_stringmysqli_errormysqli_fetch_assocmysqli_free_resultmysqli_close
Instead of using mysqli_query and mysqli_real_escape_string, use the following functions:
mysqli_stmt_initmysqli_stmt_bind_parammysqli_stmt_preparemysqli_stmt_executemysqli_stmt_bind_resultmysqli_stmt_fetchmysqli_stmt_close