PDA

View Full Version : Display most visited page on the homepage?



peejeev
13 Apr 2007, 05:36 PM
Does anyone know how to make a link on the home page of a site that goes to the most visited page on the same site. Thanks

Littlened
26 Apr 2007, 04:18 AM
Does anyone know how to make a link on the home page of a site that goes to the most visited page on the same site. Thanks

If it was me, I would create a PHP script which would be added to every page, when a page is loaded it add's an entry into a database containing the pageID. Then when you want to work out the most visited page, create a script to pull the data from the database and count the number of times each page has been visited, that's your most visited page.

You could create an entry in the database table for each page, then have a count field, and each time the page is displayed the count is retrieved from the databases and incremented by one. However this would cause problems when 2 people viewed the page at the same time. i.e. lets say the count for one of your pages is 20, the first person retreived the value and increments it by 1, so now it's 21, but before it gets chance to save the value back to the database someone else has viewed the page, retreived the count 20 incremented by 1 to make 21. This means that both pages will save the value 21 back to the database, but it should be 22.

Hope that helps.