O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - building a real-time page visit counter

We will modify the logger to add a new method that keeps track of how many times a blog post has been viewed daily. The method will store this information in a new collection, whose schema is designed to fit this new use case. We will modify the blog.php file to call that method after rendering the page. We will display this information in an HTML table on a different page.

  1. Open the log.php file and add the following method in the Logger class:
    public function updateVisitCounter($articleId) { $articleVistiCounterDaily = $this->_dbconnection ->getCollection('article_visit_counter_daily'); $criteria = array( 'article_id' => new MongoId($articleId), 'request_date' => new MongoDate(strtotime('today')) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required