Jul 25, 2008

Php Counter

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Php Counter

Reaper
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 ??

Reply

Spectre
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.

Reply

Dragonfly
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.

Reply

farsiscript
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 :

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 sad.gif

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php counter

  1. Hit Counter - simple hit counter (0)
  2. Does any one have a php counter script? - Free counter script? (15)
    Does anyone know of a good counter script i could use to display the number of clicks/hits on a
    download link on one of my sites?...
  3. Visitors Counter - With PHP (no MySQL needed!) (4)
    Well, here we will make an hit counterusing php and an *.txt file. This script is so simple, but
    very usefull. First, le'ts make an file called counter.php, with the following codes inside:
    CODE <? $file = 'counter.txt'; // this is the file where the number of visitors
    will be written $fopen = fopen("$file", "r"); // open the text
    file $count = fread($fopen, 1024); // read the text file fclose($fp);
    // close the text file $count = $count + 1; // add one more hit echo &#...
  4. One More Tut 4 U :) - Link counter (0)
    Well, in this tut, I'll show you how to do an simple link counter, with only one count for each
    IP and the date when the link were clicked. Just remember, this is only one way to do it. First,
    create an mysql database called 'links', with 2 table: first table will be called
    'links', with the columns: id, title, ref and clicks. The other one will be 3 columns and
    will be called links_info: id, ip and date. Just remember that the columns 'id' of this
    second table IS NOT auto-increment. Here is the code of the file which will count the clicks, ...
  5. Php Hit Counter - record your visitors... (1)
    All you do is copy this code into the page you want to display it on. CODE <?php
    $counterfile = "counter.txt"; $counter =
    file("$counterfile"); $c = $counter[0]; if
    (strlen($c) == 0) {$c=0;} $c=$c+1; $a =
    fopen("$counterfile", "w"); fwrite($a, $counter =
    ""); fputs($a, $c); fclose($a); echo
    ("$c"); ?> Make a file called 'counter.txt' in the same ...



Looking for php, counter

Searching Video's for php, counter
advertisement



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