Jump to content

How to create page views for every pages?


Recommended Posts

Whenever the page is viewed, you need to insert the user's IP ($_SERVER['REMOTE_ADDR']) and the name of the page into the database. Then you can find out how many unique visitors you've had with this SQL query:

SELECT COUNT(DISTINCT ip) FROM visitors WHERE page = '/pagename.php'

On my website, I've gone further and also logged the user's browser ($_SERVER['USER_AGENT']), referrer (the page they came from, $_SERVER['HTTP_REFERER'] (sic)), and location. You can do these things with Google Analytics, but I wanted to figure out how to do it with PHP.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...