vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   PHP Mini Hit counter for vB (https://vborg.vbsupport.ru/showthread.php?t=44122)

Thomas P 09-30-2002 12:50 PM

PHP Mini Hit counter for vB
 
Hello,

I'm looking for a simple hit counter for my forumhome page.

Currently I use a snippet which breaks every x hours :(

It is a file based counter I inserted into the phpinclude template and I echo the figures with variables.

What it does is it shows me daily hits, which reset every 24h and total hits with all hits since the beginning.

Does anyone has an alternative to my counter which doesn't break?

Many, many thanks,
-Tom

g-force2k2 09-30-2002 04:42 PM

what do you mean doesn't break?

If im correct in understanding what you mean... you can use mysql to store the data to get the effect you're looking for...

PHP Code:

CREATE TABLE hits (
  
hitid int(10unsigned NOT NULL DEFAULT '0',
  
hitname varchar(30NOT NULL,
  
hits int(10NOT NULL DEFAULT '0',
  
PRIMARY KEY(hitid)
)

INSERT INTO hits VALUES ('1''index''0'

run those two queries and then open index.php

find:

PHP Code:

eval("dooutput(\"".gettemplate('forumhome')."\");"); 

above it add:

PHP Code:

$DB_site->query("UPDATE hits SET hits=hits+1 WHERE hitname='index'");
$hits $DB_site->query_first("SELECT hits FROM hits WHERE hitname='index'");
$hits $hits['hits']; 

then in your forumhome tempate place $hits whereever you want the hits to show... i doubt this is the most effective way but it should do the trick ;)

regards...

g-force2k2

Thomas P 10-01-2002 08:58 AM

Thanks g-force2k2,

I'll try it :)

Quote:

what do you mean doesn't break?
I don't know why, but my textcounter "breaks" sometimes, i.e. resets all numbers and starts to count from 0 :(

Thank you very much, I think what you posted here is that what I need, but I need one more thing ;)
Is it difficult to add a figure which shows the number of daily users (e.g. $hitsdaily)? :)

Thanks,
-Tom

Thomas P 10-02-2002 06:51 AM

Please stay with me :)

Just this one little addition would make my users happy :)

Thank you,
-Tom

NTLDR 10-02-2002 10:32 AM

Why not install vBstats? This has many statistics for you, like hits per day, total, thread views total, users online in a day, posts in the last 24 hrs etc...

Thomas P 10-02-2002 12:11 PM

Yeah, I know...

I just need to replace my old counter, which'll exist next to vBstats.

http://www.mcseboard.de/ - I have to figures, down to the right, dark shaded is the number of Hits sinc 05/2001 (would be $hits in g-force2k2 hack)

and the number of "guest hits", which is the number of $hits in the last 24h

Thanks anyway, :)
-Tom

Thomas P 10-09-2002 06:34 AM

Here's the file based counter I use now, which breaks ~3 times a day:

Code:

// ipcounter hack by CX
// config
// create these two files count.txt and ip.txt, chmod them to 777
$count_file = "counter.txt";
$ip_file = "counter_ip.txt";
$userip = getenv('REMOTE_ADDR');  // in some fixed IP server, change this line to $userip = getenv('HTTP_X_FORWARDED_FOR');

$count_temp=file($count_file);
$ip_temp=file($ip_file);

$detail=explode("|",$count_temp[0]);
$count_t=getdate(time());
$count_day=$count_t['mday'];

if ($detail[0]==$count_day) {
    $detail[1]++;
    $detail[2]++;

    $count=count($ip_temp);
    $check=1;
    for ($i=0; $i<$count; $i++) {
        $ip_list=str_replace("\r","",str_replace("\n","",$ip_temp[$i]));
        if ($ip_list==$userip) $check=0;
    }
    if ($check==1) {
        $detail[3]++;
        $detail[4]++;
        $fp=fopen($ip_file,"a");
        flock($fp,3);
        fputs($fp,$userip."\n");
        fclose($fp);
    }
}
else {
    $detail[0]=$count_day;
    $detail[1]=1;
    $detail[3]=1;
    $detail[2]++;
    $detail[4]++;
    $fp=fopen($ip_file,"w");
    flock($fp,3);
    fputs($fp,$userip."\n");
    fclose($fp);
}

$new=implode("|",$detail);
$fp=fopen($count_file,"w");
flock($fp,3);
fputs($fp,$new);
fclose($fp);

// end ipcounter hack

$i = $HTTP_GET_VARS['i'];

Thanks,
-Tom

Thomas P 10-15-2002 09:29 AM

Okay, I took a ready made script and integrated it into vB
http://www.needscripts.com/Resource/1447.html

Sad how few support someone can get over here with an easy thing like a counter. I'm not trying to be sarcastic or anything, it's just a fact and I'm curious...


All times are GMT. The time now is 01:04 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.01026 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete