Jump to content
xisto Community
Sign in to follow this  
Reaper

Php Counter

Recommended Posts

Of course it's possible (and incredibly simple). Just store an integer value in some form of database (flat file, MySQL, or whatever), and increase it every time a user visits your page. You could get slightly more complex and only count unique visitors using cookies, IP addresses, or both.

Share this post


Link to post
Share on other sites

A simple counter, just to count the number of visitors may be simple but to be able to know the behaviour of the website visitors is a very complex programme to code. Are you satisfied only with simple counter? As a webmaster I don't think you will say YES. I suggest you to rather use web site visitor counters like statcounter dot com, sitemeter dot com and others. Especially statcounter is very powerful and good. I rather recommend you to go for this one.

Share this post


Link to post
Share on other sites

Yes , You have 2 Way :

1 - User Cpanel counter ( In Your Cpanel CGIScript You can find Counter That Work With CGi , You can Manage Counter Skin and .... You Must Put That code To Your site )

2 - Write Counter Code With PHP :

 

<?php //part1$page=$_SERVER['PHP_SELF']; //part2//fill in the correct values below $connection = mysql_connect("mysql server","username","password"); //part3mysql_select_db("database"); //part4$result = mysql_query("SELECT * FROM counter WHERE page='$page'",$connection); $sql=""; $count=1; if(mysql_num_rows($result)==0)//we don't have a record for it { //part5$sql=<<<SQL INSERT INTO counter VALUES( '$page', 1 ) SQL; } else if(mysql_num_rows($result)>0) {//part6$sql=<<<SQL UPDATE counter SET count=count+1 WHERE page='$page' SQL; $array=mysql_fetch_assoc($result); $count=$array['count']; } //part7$newResult = mysql_query($sql,$connection); //part8print $count+1; mysql_close($connection); ?>

Put Above code To Your Page . like Index.php or ..... but its must php file

 

part 1 : Get Page Url or Page Location

Part 2 : Connect To SQL

* mysql server : localhost

* username : Your MYSQL username

* Password : Your MySql Password

** You can make one MySQL Database in Cpanel / Manage SQL

part3 : Chooise Database , You Must write Your Database name in "database"

Part 4 : Get Number in Database , for example 4,5,6,7,8

Part 5 : If Your Database is null Wirte 1 in your Database Vule

Part 6 : Get SQL vule and Put Number in $count variable

Part7 : Make Query

part8 : Add one number to Counter number and Write in SQL

 

thanks all, so sorry my english is not very good :lol:

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.