How can I maintain the count of how many persons have hit my site?

Showing Answers 1 - 33 of 33 Answers

Prasanna

  • Jul 10th, 2006
 

First of all we have to make one text file to store the no of value the user hit..At th first time the file count vatriable is 0 then every time when the form is load and user click on that form at that time we open the file and increment the counter variable ....by one ,,,, then close the file in this way we can find that how many time the the page is hitted by the user .....By :- Prasanna R Raval

  Was this answer useful?  Yes

Revathy

  • Jul 25th, 2006
 

hi i am revathy,i would like to know more on php so can u send me an example for the above question pls.waiting for ur reply.pls do reply me

  Was this answer useful?  Yes

Maheswara

  • Aug 2nd, 2006
 

By using setcookies we can get count ..

//include this code inside php tagsession_start();//error_reporting(E_ALL);if(!isset($_SESSION['count'])){ $_SESSION['count']=0;}else{ $_SESSION['count']++;}echo "session".$_SESSION['count'];//remove the html comment

Amol

  • Aug 16th, 2006
 

The best way is to use session variales.

So that whenever a user hits web-page ,

we can increment the counter in the session variable set for number of usres. 

sasikumar

  • Oct 4th, 2006
 

ya get every time user ip using this function $userIP = $_SERVER['REMOTE_ADDR'];sotre database.finaly get $users=mysql_num_rows();print $user;bySasi

  Was this answer useful?  Yes

Ramesh

  • Oct 27th, 2006
 

in your database maintain seperate table visitor detail ,for example you have visitor_det table filed is count_visitor In your index file put on the particular code: mysql_query("update visitor_det set count _visitor+1"); Whenever ever index file opened so that query will execute

  Was this answer useful?  Yes

sen

  • Nov 29th, 2006
 

using session we can do that

  Was this answer useful?  Yes

Varghese

  • Dec 12th, 2006
 

hi

  U maintain these counter in table

  table Name = tblCounter

  Fields = ID , CouterValue

  insert the values in id = 1 and counterValue = 0

  Get the countervalue through select query like "select CouterValue from tblCounter where id =1

and increment the CounterValue by 1 as newCountervalue

and update the newCounterValue like

  "update tblCounter set counterValue = newCounterValue where id=1"

 these functionality done in index page(FirstPage)

seban

  • Apr 4th, 2007
 

First of all we have to make one text file to store the no of value the user hit..At th first time the file count vatriable is 0 then every time when the form is load and user click on that form at that time we open the file and increment the counter variable ....by one ,,,, then close the file in this way we can find that how many time the the page is hitted by the user .....By :- seban

  Was this answer useful?  Yes

Anand.k

  • Nov 18th, 2007
 

by using only cookie with a small time limit we can get exact hit from the user here session creates false hit when page is  refreshed.  

  Was this answer useful?  Yes

msdwivedi

  • Dec 28th, 2007
 

This may be achived through maintaining tables, session is not a good idea.
create a table:
CREATE TABLE `visits` (
  `id` int(11) NOT NULL auto_increment,
  `ip_address` varchar(15) NOT NULL default '',
  `referer` varchar(250) NOT NULL default '',
  `visit_date` date default NULL,
  `visit_time` time NOT NULL default '00:00:00',
  `visit_page` varchar(35) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

you can get IP address of visitor by $_SERVER['REMOTE_ADDR']
in your script create a function that checks that current date and ip and visited page not match if this function returns true insert new entry.
Make two function 1 is to get total visit on site today and 2nd is for  total visits from now on.
the interesting thing is you can also maintain history, you can note down referers you can also count the visit of each page today or on past etc.

maurani

  • May 5th, 2008
 

$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];

  Was this answer useful?  Yes

amitverma

  • Feb 6th, 2009
 

USE this code (It can NOT be simpler than this) -


$file = fopen("counter.txt", ’a+’);
if ($file == false) {
 die ("Unable to open/create file");
}
if (filesize("counter.txt") == 0) {
 $counter = 0;
} else {
$counter = (int) fgets($file);
}
ftruncate($file, 0);
$counter++;
fwrite($file, $counter);
echo "There has been $counter hits to this site.";

Now your server will have a file counter.txt, which will have a count for hits on your site. Add this code at the bottom of every page(you may include it using a file also), and it will have a complete log/count.


-- Amit Verma

  Was this answer useful?  Yes

abc

  • Sep 12th, 2011
 

By using setcookies we can get count

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions