O'Reilly logo

PHP for Teens by Maneesh Sethi

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

Creating a Web Page Counter

Okay, let’s try something new. Now that you know about basic session variables, let’s create a web page counter. This counter will recognize how many times a visitor has visited your page and display the number on the screen. The counter starts at 0 when the page is closed.

Developing a counter requires just a little PHP. We will open a session and reference the counter (which creates the variable if it doesn’t exist, or increments it if it does exist). The following code fragment is taken from phpft13-04.php:

<?php session_name("counter"); session_start(); header("Cache-control:private"); $_SESSION['counter']++; echo "Hey, welcome to this web page. While you are here, feel free to browse some other sites. Just make ...

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