Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2003, 09:58 PM
Slynderdale Slynderdale is offline
 
Join Date: Mar 2002
Location: New York State
Posts: 576
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Hit Counter Script

Heres a counter I quickly made for a freind, it uses no cookies and so on, it stores the useragent and host of the person instead. You can also esily reset the counter any time you want by going to:
http://yoursite/counter.php?action=r...sword=password

Also if some one tries to access the counter file, they'll get a 404 error. Also the counter wont count the person accessing the counter file itself.

How to use the script on your site:
All you have to do is include/require the counter file any wheres inside the site where you want to keep track of the hits. For example, if you have a php file all you have to do is add include('counter.php'); just below the <?.

If your index/or the page you wanna keep track of hits is an html file, change it to file.php (can be what ever you choose) and at the top have <? include('counter.php'); ?>, you can leave the rest of the html intact.

Instead of printing the hit data directly out, the data is stored within varibles so you can esily customise the looks. Just place the varible any wheres you want for example:

echo "Total Hits: $counter_total";

or if you renamed a html file to php as stated before, you can use:

<? echo "Total Hits: $counter_total"; ?>

The password for the reset can be what ever you want, theres a setting inside a file where you can set it.

Heres what data this stores about the person:
Host (ip)
Reseloved Host
User Agent
Port
Referer
Timestamp

So if you wanted to could esily make a script that accesses this data for example for a list of referering sites and so on.

Heres what varibles the counter uses and what they are used for:

$counter_twentyfour - Gets the hits in the last 24 hours
$counter_total - Gets the total hits
$counter_today - Gets the total hits today
$counter_uniquetwentyfour - Gets the unique hits in the last 24 hours
$counter_uniquetotal - Gets the unique total hits
$counter_uniquetoday - Gets the unique today hits
$counter_lasthit - Gets the date and time of the last hit
$counter_start - Gets the date and time of when the counter started

Heres the query you need to run:

CREATE TABLE hit_data (
hitid int(10) unsigned NOT NULL auto_increment,
host varchar(20) NOT NULL default '',
resolvedhost varchar(100) NOT NULL default '',
useragent char(100) NOT NULL default '',
port int(10) unsigned NOT NULL default '0',
referer varchar(255) NOT NULL default '',
timestamp int(10) unsigned NOT NULL default '0',
PRIMARY KEY (hitid)
) TYPE=MyISAM;

Note: The query and this info being posted are already located in the PHP file for future refrence.

All you have to do is edited a few settings and upload and thats it, heres the settings:

// Mysql Data
$counter_server = "localhost";
$counter_database = "root";
$counter_user = "root";
$counter_password = "";
$counter_usepconnect = false;
//------
$script_name = "counter.php"; //The actual script name of the counter
$script_password = "default"; //Password used to reset the counter
$date_time_format = "F j, Y, g:i:s a"; //The date format for the counter
// See http://www.php.net/date

If you have any questions or comments or need help feel free to post them.


It can only be used as long as the copy right text isnt edited or removed from the php file and as long as you dont take credit for it. That is all.
Attached Files
File Type: php counter.php (7.5 KB, 42 views)
Reply With Quote
  #2  
Old 05-30-2003, 03:32 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting idea - good to see you around again

- miSt
Reply With Quote
  #3  
Old 12-23-2003, 12:00 PM
irn-bru's Avatar
irn-bru irn-bru is offline
 
Join Date: Feb 2002
Location: Scotland
Posts: 98
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

there seems so be a error on line 43 $date_time_format
Reply With Quote
  #4  
Old 12-24-2003, 07:06 AM
Slynderdale Slynderdale is offline
 
Join Date: Mar 2002
Location: New York State
Posts: 576
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Copy and paste your line 43 and I'll see whats wrong.
Reply With Quote
  #5  
Old 12-25-2003, 11:47 AM
irn-bru's Avatar
irn-bru irn-bru is offline
 
Join Date: Feb 2002
Location: Scotland
Posts: 98
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$date_time_format = "F j, Y"; //The date format for the counter
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 07:44 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04087 seconds
  • Memory Usage 2,216KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (1)postbit_attachment
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete