Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
Donovan
Client


Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Wed Mar 29, 2006 9:37 am Reply with quote

I want to add something to Ravens block-User_Info.php block.

At the very end of his block he has the following:

Code:
/* Hits in Total */

   $totalhits = 0;
   $result = sql_query("SELECT sum(hits) FROM $prefix"._stats_year."", $dbi);
   list($totalhits) = sql_fetch_row($result, $dbi);
   $content .= "<center><small>"._WERECEIVED."</small><br />\n";
   $content .= "<b>$totalhits</b><br />\n";
   $content .= "<small>"._PAGESVIEWS."<br />$startdate</small></center>";
   $content .= "<hr noshade>";
if (is_user($user)||is_admin($admin)) {
   $content .= "<center>"._BHITS." "._BTD.": <b>$today</b><br />";
   if (is_admin($admin)) {
      $content .= ""._BHITS." "._BYD.": <b>$yesterday</b><br /></center>";
   }
   else $content .= "</center>";
}
if ($showServerDateTime || ($showServerDateTimeAdmin&&is_admin($admin))) {
if (is_user($user)||is_admin($admin)) {
   $content .= "<hr noshade>";
}
   $sdt = date("j F Y\nH:i:s T");
   $zone = date("Z")/3600;
   if ($zone >= 0) {
      $zone = "+".$zone;
   }
   $content .= "<center>"._SERDT."<br />$sdt (GMT $zone)</center>";
}
$content .= "</form>";

?>


I want to insert a code somewhere for a graphical unique hits counter. The counter I found is from

Simp Counter 1.1
Code by deadserious Only registered users can see links on this board! Get registered or login!

The instruction tell me to insert this on every page I want the counter, but I would rather add this to Raven block at the bottom.

Code:
//Unique Hits

   $content .= "<hr noshade>";
   $content .= "<center>Unique Hits</center>";
 include "/home/xxxxxx/public_html/scripts/simpcounter/simpcounter.php";



Or if I look at the end of simpcounter.php I find:

Code:
$curcount = substr( $count, $i, 1 );

        echo "<a href=\"http://speedycode.com/archives/17-Simp-Counter-1.1-Released.html\"><img src=\"$imgdir$curcount$imgext\" border=\"0\" alt=\"PHP Counter\"></a>\n";


Could I include the simpcounter.php file and just echo "><img src=\"..scripts\$imgdir$curcount$imgext\ out in the block.

Could somebody give me an example?

here is simpcounter:

Code:
<?php


// CONFIGURATION SECTION - You CAN EDIT THE SETTINGS BELOW  // 

$countfile = '/home/xxxxxxxx/public_html/scripts/simpcounter/count.txt';               
# The system path to the count log file. You need to change this.

$iplogfile = '/home/xxxxxxxx/public_html/scripts/simpcounter/iplog.txt';               
# The system path to the ip log file. You need to change this.

$imgdir = 'http://www.eto-league.com/scripts/simpcounter/';   
# The url to the directory contatining your images including the traling slash

$imgext = '.gif';                   
# The extension of your images, ( jpg, png, etc. )

$usetextcounter = 0;                   
# 1 = use text based hit counter, 0 = use graphical counter

$countonlyunique = 1;                   
# 0 = count all hits/pageloads, 1 = count only unique visits

$useflock = 1;                       
# 1 = use file locking, 0 = don't.


// END CONFIGURATION SECTION //


// Lock and/or read or write file //
function lock_r_w ( $file , $mode, $content, $useflock )
{
    if ( is_writeable( $file )) {
        $fh = fopen( $file, $mode );
            if ( $useflock == 1 )
            {
                if ( flock( $fh, LOCK_EX ))
                {
                    if ( $mode == 'r' )
                    {
                        return fgets( $fh );
                    }
                    else
                    {
                        fwrite( $fh, $content );
                    }
                    flock( $fh, LOCK_UN );
                }
                else
                {
                    fclose( $fh );
                    echo "Couldn't lock the file $file.<br />
                    Your system may not support file locking.<br />
                    You probably need to change \$useflock to 0.";
                    exit;
               }
            }
            else
            {
                if ($mode == 'r') {
                    return fgets($fh);
                }
                fwrite( $fh, $content );
            }
        fclose($fh);
    }
    else
    {
        echo "The file $file is not writeable.<br />
        Change the permissions and try again.";
        exit;
    }
}


$count = lock_r_w( $countfile, "r", '', $useflock );
if ( $count == 0 ) { $count = 1; }

if ( $countonlyunique == 1 )
{
    $curtime = getdate();

    # Empties the ip log file if script is accessed between 12 and 12:01 AM #
    # Hopefully someone will access your page between 12 and 12:01 AM :D #
    # If you have cron access and are using this as a unique visitor counter #
    # you should set up a cron job to access this script between 12:00 and 12:01 #
    # AM so that you will have an accurate count of unique visitors per day #
    # Visit http://speedycode.com for help and questions with setting up cron jobs #
 
    if ( $curtime['hours'] == 00 && $curtime['minutes'] == 00 )
    {
        lock_r_w( $iplogfile, "w", "", $useflock ); 
    }

    $ip = getenv( "REMOTE_ADDR" );
    $ips = lock_r_w( $iplogfile, "r", '', $useflock );
    $curips = explode("|", $ips);
   
#    foreach ( $curips as $key => $value )
#    {
#        $curips[$key] = trim( $value );
#    }

    $curvisitor = ( in_array( $ip, $curips )) ? 1 : 0;
   
    if ( $curvisitor != 1 )
    {
        lock_r_w( $iplogfile, "a", "$ip|", $useflock );
        lock_r_w( $countfile, "w", $count+1, $useflock );
    }
}
else
{
    lock_r_w( $countfile, "w", $count+1, $useflock );
}

if ( $usetextcounter == 1 )
{
    echo $count;
}
else
{
    for( $i = 0; $i < strlen( $count ); $i++ )
    {
        $curcount = substr( $count, $i, 1 );
        echo "<a href=\"http://speedycode.com/archives/17-Simp-Counter-1.1-Released.html\"><img src=\"$imgdir$curcount$imgext\" border=\"0\" alt=\"PHP Counter\"></a>\n";
    }
}

#################################################
# Simp Counter 1.1                              #
# Code by deadserious                           #
# http://www.speedycode.com                     #
#                                               #
#                                               #
#                                               #
#################################################

?>



*edit*

I'm thinking something like this at or near the end


Code:
$content .= "<hr noshade>";

$content .= "Unique Hits";
$content .= "<img src=\"scripts/simpcounter/$imgdir$curcount$imgext\" border=\"0\" alt=\"Unique Hits Counter\"></a>\n";


Last edited by Donovan on Fri Mar 31, 2006 11:17 am; edited 1 time in total 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Fri Mar 31, 2006 10:39 am Reply with quote

Assume that simpcounter is in then includes folder.

Modify this line in simpcounter from

echo "<a href=\"http://speedycode.com/archives/17-Simp-Counter-1.1-Released.html\"><img src=\"$imgdir$curcount$imgext\" border=\"0\" alt=\"PHP Counter\"></a>\n";


to

$content .= "<a href=\"http://speedycode.com/archives/17-Simp-Counter-1.1-Released.html\"><img src=\"$imgdir$curcount$imgext\" border=\"0\" alt=\"PHP Counter\"></a>\n";


Then, use this code:
$content .= "<hr noshade>";
$content .= "Unique Hits";
include ("includes/simpcounter.php");
 
View user's profile Send private message
Donovan
PostPosted: Fri Mar 31, 2006 11:16 am Reply with quote

Worked like a charm.

Your the best.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©