| | 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 ?? |
|
|
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.
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.
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 : CODE <?php //part1 $page=$_SERVER['PHP_SELF']; //part2 //fill in the correct values below $connection = mysql_connect("mysql server","username","password"); //part3 mysql_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); //part8 print $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
Similar Topics
Keywords : php counter
Well, here we will make an hit counterusing php and an *.txt file. This script is so simple, but Well, in this tut, I'll show you how to do an simple link counter, with only one count for each All you do is copy this code into the page you want to display it on. CODE <?php Looking for php, counter
|
|
![]() Php Counter |
| ADD REPLY / Got an Opinion! | Remove these ADs! | RAPID SEARCH! | Free Web Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute more info. to help others. Ask your Doubts & Queries to get answers, So that "Together We can help others!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|