Delphi For PHP Forums       


Go Back   Delphi-PHP Forums > Programming > PHP - Code Snippets
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

PHP - Code Snippets Functional Code Snippets that other people may find useful. Post them here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 31st March 2007, 11:33
just Joined!
 
Join Date: Mar 2007
Posts: 1
pakala venkata s is on a distinguished road
Default pls give me a php code snippet to track the number of users who hit a page

with out using database? pls give me a php code snippet to track the number of users who hit a page with out using database
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 31st March 2007, 11:46
just Joined!
 
Join Date: Mar 2007
Posts: 1
warjolt is on a distinguished road
Default

If you want a REAL basic hit counter just open a file and everytime someone goes to the website increment that number in the file. In any case you need to store the number of hits somewhere. Usually you'll want to use something like cookies or IP addresses so you don't count the hits again when someone clicks reload a thousand times.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 31st March 2007, 11:47
just Joined!
 
Join Date: Mar 2007
Posts: 1
qwert is on a distinguished road
Default

I do not know php, but hope this helps

http://www.tutorialstream.com/tutori...ts_counter.php

http://www.tizag.com/tools/counter.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 3rd April 2007, 01:59
D4PHP User
 
Join Date: Apr 2007
Location: Connecticut
Posts: 40
Ryan is on a distinguished road
Default

So, here is what your going to do... (taken from http://www.tutorials-expert.com/tuto...out-MySQL.html)

1) Create a file called visits.txt and simple type a 0 and save the file to your server.
2) Create a file called counter.php and enter in the following code
PHP Code:
<?php $myfile "visits.txt";
//we assign our file name to the variable we'll use to handle it
if(file_exists($myfile))//if the file exists
{
//we run our counter script $var = fopen( $myfile,\'r+\');
//opens in read and write mode our file
$visits fread($var,filesize($myfile));
//puts the content of the file for its whole lenght
rewind$var );
//resets the file position indicator to the beginning
$visits++; //increments the actual number of vists by 1
fwrite($var$visits);
//writes in the variable the actual (incremented) value
fclose($var);//closes our file reference
}
else
{
print 
"File $myfile doesn\'t exist...";
Die();
//if the file doesn't exist prompts a warning and kills the script
}
$message sprintf("%s visitors since 08/20/2005.",$visits);
//saves our visits message in a variable ($message) that will be used as output
print $message;
?>
3) If you want to include it in your page just use this html
HTML Code:
<html>
<body>

<?php include 'counter.php'; ?>

</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 18th April 2007, 16:29
D4PHP User
 
Join Date: Mar 2007
Posts: 24
professor is on a distinguished road
Default

Thats true but in text file you will get counter incremented by one when user will refresh the page. I would prefer to set the variables at page load first time and then check for that variable using isset() to check whether user is refreshing page or not.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 18th April 2007, 18:27
D4PHP User
 
Join Date: Apr 2007
Posts: 72
Trumpetx is a glorious beacon of lightTrumpetx is a glorious beacon of lightTrumpetx is a glorious beacon of lightTrumpetx is a glorious beacon of lightTrumpetx is a glorious beacon of lightTrumpetx is a glorious beacon of light
Default

Quote:
Originally Posted by professor View Post
Thats true but in text file you will get counter incremented by one when user will refresh the page. I would prefer to set the variables at page load first time and then check for that variable using isset() to check whether user is refreshing page or not.
or, set a cookie... it's not 100% foolproof, but it works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 21st April 2007, 14:19
D4PHP User
 
Join Date: Apr 2007
Posts: 10
flymanj will become famous soon enough
Default

My own opinion is that it is better to store such info a table into the database. in that way you could store not only that somebody has hit the page but also and information about the system that he/she is using and the sessionID, in that way you will be able to track the not only the count of the pages that are hit but also and the individial sessions. Also you could store and the ip and domain from that the user is accessing you.

Beside that technique the best solution to track the users that are using your page of course is made by Google. Check the google analytics: http://www.google.com/analytics/

Best Regards,
Yani
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 23:08.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use