Reaper 0 Report post Posted April 11, 2006 is it possible to use php to make a counter on a website and if it is does anyone know code for an effective one ?? Share this post Link to post Share on other sites
Spectre 0 Report post Posted April 11, 2006 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
Dragonfly 0 Report post Posted April 11, 2006 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
farsiscript 0 Report post Posted April 16, 2006 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 Share this post Link to post Share on other sites