Hallo, Gast! (Registrieren)

Wir wünschen allen Besuchern frohe Ostern!

Letzte Ankündigung: MyBB 1.8.37 veröffentlicht (04.11.23)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
Hitcounter für myBB
#1
Ich bräuchte einen Hitcounter für myBB mit IP-Sperre entweder als plugin oder auf andere Weise. Das Skript welches ich versuchte einzubinden zählt quasi mit include den aktuellen Hit gar nicht, sondern nur wenn ich es im Browser direkt aufrufe. Das ist schon komisch. Ich weis einfach nicht mehr weiter. Hier der Skriptcode in der "counter.php", die ich als include-Datei in meine Forum Index einbauen wollte.
Der Counter zählt nur, wenn man die Counter.php direkt besucht. Als include Datei werden alle Befehle ignoriert und er gibt nichts aus und macht auch nichts.
Gibt es für MyBB da ein Plugin vielleicht?
Ich fand nichts nur ein sehr langsames auf mybb.net welches das Forum erheblich ausbremst und nicht für meine Version ist.

Anbei das untere Skript was nicht geht bloß mal infohalber:

PHP-Code:
<?php

/**
* @author    Eric Sizemore <admin@secondversion.com>
* @package   SV's Simple Counter
* @link      www.secondversion.com
* @version   1.7.0
* @copyright (C) 2006 - 2008 Eric Sizemore
* @license   {@see LICENSE.txt} GNU Public License
*/

// #################### Define Important Constants ####################
// There should be no need to edit these
define('COUNT_FILE''logs/counter.txt');
define('IP_FILE''logs/ips.txt');

// ######################## USER CONFIGURATION ########################
// Edit the following.. true = yes, false = no

// Use file locking?
define('USE_FLOCK'true);

// Count only unique visitors?
define('ONLY_UNIQUE'true);

// Show count as images?
define('USE_IMAGES'false);

// Path to the images
define('IMG_DIR''images/');

// Image extension
define('IMG_EXT''.gif');

// ############################ Functions #############################
/**
* We use this function to open, read/write to files.
*
* @param  string   Filename
* @param  string   Mode (r, w, a, etc..)
* @param  string   If writing to the file, the data to write
* @return mixed
*/
function fp($file$mode$data '')
{
    if (!
file_exists($file) OR !is_writable($file))
    {
        
trigger_error("Error: '<code>" htmlspecialchars($file) . "</code>' does not exist or is not writable.");
    }

    if (!(
$fp = @fopen($file$mode)))
    {
        
trigger_error("Error: '<code>" htmlspecialchars($file) . "</code>' could not be opened.");
    }

    if (
USE_FLOCK AND @flock($fpLOCK_EX))
    {
        if (
$mode == 'r')
        {
            return @
fread($fpfilesize($file));
        }
        else
        {
            @
fwrite($fp$data);
        }
        @
flock($fpLOCK_UN);
    }
    else
    {
        if (
$mode == 'r')
        {
            return @
fread($fpfilesize($file));
        }
        @
fwrite($fp$data);
    }
    @
fclose($fp);
}

/**
* Get the users ip address.
* Pulled from my {@link http://www.domainportfolio.us Domain Portfolio} project.
*
* @param  none
* @return string
*/
function getipadresses()
{
    
$ip my_getenv('REMOTE_ADDR');

    if (
my_getenv('HTTP_X_FORWARDED_FOR'))
    {
        if (
preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s'my_getenv('HTTP_X_FORWARDED_FOR'), $matches))
        {
            foreach (
$matches[0] AS $match)
            {
                if (!
preg_match('#^(10|172\.16|192\.168)\.#'$match))
                {
                    
$ip $match;
                    break;
                }
            }
            unset(
$matches);
        }
    }
    else if (
my_getenv('HTTP_CLIENT_IP'))
    {
        
$ip my_getenv('HTTP_CLIENT_IP');
    }
    else if (
my_getenv('HTTP_FROM'))
    {
        
$ip my_getenv('HTTP_FROM');
    }
    return 
$ip;
}

/**
* Returns an environment variable. Based on PMA_getenv from phpMyAdmin.
*
* @param  string  Variable name, eg: PHP_SELF
* @return string
*/
function my_getenv($varname)
{
    if (isset(
$_SERVER[$varname]))
    {
        return 
$_SERVER[$varname];
    }
    else if (isset(
$_ENV[$varname]))
    {
        return 
$_ENV[$varname];
    }
    else if (
getenv($varname))
    {
        return 
getenv($varname);
    }
    return 
'';
}

// ######################## Start Main Script #########################
// Get current count

$count fp(COUNT_FILE'r');

// Do we only want to count 'unique' visitors?
if (ONLY_UNIQUE)
{
    
// Get visitor ip and check against our ip log
    
$ip getipadresses();
    
$ips trim(fp(IP_FILE'r'));
    
$ips preg_split("#\n#"$ips, -1PREG_SPLIT_NO_EMPTY);
    
$visited = (bool)(in_array($ip$ips));

    
// They've not visited before
    
if (!$visited)
    {
        
fp(IP_FILE'a'"$ip\n");
        
fp(COUNT_FILE'w'$count 1);
    }
    
// Memory saving
    
unset($ips);
}
else
{
    
// No, we wish to count all visitors
    
fp(COUNT_FILE'w'$count 1USE_FLOCK);
}

// Do we want to display the # visitors as graphics?
if (USE_IMAGES)
{
    
$count preg_split("##"$count, -1PREG_SPLIT_NO_EMPTY);
    
$len count($count);
    
$display '';

    for (
$i 0$i $len$i++)
    {
        
$display .= '<img src="' IMG_DIR $count[$i] . IMG_EXT '" border="0" alt="' $count[$i] . '" />&nbsp;';
    }
    echo 
$display;
}
else
{
    
// Nope, let's just show it as plain text
    
$count=$count;
}

?>
In der Politik ist es manchmal wie in der Grammatik: Ein Fehler, den alle begehen, wird schließlich als Regel anerkannt.
André Malraux
Zitieren