[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

How to add visitors code in the website in php.

I want to implement No. of visitors code in php. What is logic for that and how to do that.
0
searchsanjaysharma
Asked:
searchsanjaysharma
  • 2
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this may work for you:
http://code.google.com/p/simphp/
0
 
Mark BradyCommented:
There are many ways to count the number of visitors from using cookies to track unique visitors or just a simple php counter to count everytime someone loads your page.

The latter is very simple. Somewhere one the page you want to count put something like this.

<?php
// get the current page count so you can display it
$query = "SELECT `count` FROM `page_count` WHERE `pageid`1 = 'your page title here'";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {
$count = $row['count']; // don't forget the single quotes
}

// increament so you get this current page view
$count ++;

// increament the page count in the database
$sql = "UPDATE `page_count` SET `count` = '".$count."' WHERE `pageid` = 'your page title here'";
mysql_query($sql) or die(mysql_error());

?>

Each of your pages will or should have a title so you could put them in a table and just increment the count for each page. Everytime your page is requested it will run this code and then you have your totals.
0
 
searchsanjaysharmaAuthor Commented:
tx
0
 
Mark BradyCommented:
Was that what you needed?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now