How to count number of visitors for a page? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

How to count number of visitors for a page?

16th Jul 2017, 11:37 AM
Jayaprakash Pediredla
Jayaprakash Pediredla - avatar
2 Réponses
+ 7
There are two methods available to count the number of viewers on any webpage(PHP): Database TechniqueUsing PHP Session variables In database technique, whenever a PHP page say yourpage.php is accessed, you maintain a count e.g in your system you must be storing User Profile Information in a database table. In the table, where name,gender,address and other information is stored , you may create a table column (page_count). Whenever user logs in (applicable for authenticated user) , you increase the count of table column value by 1 for corresponding user. You may also record IP Address in the same way from your page is accessed for the corresponding user. For anonymous user, user profile information will not be available. So you can increase the value of page_count against corresponding IP Address from where yourpage.php is called from browser. Using PHP Session variables, you can start PHP session by calling PHP function session_start(); And set a session variable like this , $_SESSION['page_count'] = strval(intval($_SESSION['page_count']) + 1) ; Later on you can dump the value of session variable $_SESSION['page_count'] in database also as per your requirement or choice. I hope this gives you idea to count the number of viewers on any webpage(PHP). Please note that the above techniques can be applied to other server-side scripting languages also like JSP or The Official Microsoft ASP.NET Site as per their syntax.
16th Jul 2017, 11:55 AM
Art456
Art456 - avatar
+ 4
By counting page request on server side (what means storing the value and increment it as each request), with or without IP discrimination (count of page viewed or of unique visitors)...
16th Jul 2017, 11:57 AM
visph
visph - avatar