Hi all php experts,
Need some help here. I need a hit counter for use in an Intranet.
Unlike the Internet, where i can hook on to an external server.
Intranet means I need the code itself for the counter to work.
Can anyone recommend a basic code for such a counter.
Well be very grateful,
An amature programmer
2 6609
Hi there,
hope the below sample will help you to get started.. good luck my fren.. -
Note: You will need to find some digits from somehere, name them as 0.gif, 1.gif, 2.gif etc. The
-
counter logs hits only, there is no support for cookies or host logging in this version.
-
-
To get it to work, simpy modify the code bellow this paragraph where appropriate and upload
-
to your server. Then on php3 pages which you want the counter to appear, use
-
-
<? include("script location"); ?>
-
-
<?
-
-
///////////////////////////////////////////////////////////////////////////////////
-
//|
-
$fileloc = "/home/mysite/hits.txt";
-
//|
-
//| Change this to the url directory containing the images, including trailing /
-
//|
-
$imagedir = "http://www.mysite.com/images/";
-
//|
-
//| If the counter is broken, or there is a problem, it will display nothing unless you set this to 1
-
//|
-
$debug = 0;
-
//|_________________________________________________________________________
-
________
-
////////////////////////////////////////////////////////////////////////////////////
-
-
-
if(is_file($fileloc))
-
{
-
if($hits = file($fileloc) AND $file = fopen($fileloc, "w"))
-
{
-
$hits = trim($hits[0]) + 1;
-
fputs($file, $hits);
-
$length = strlen($hits);
-
fclose($file);
-
$file = fopen($fileloc, "r");
-
echo "<table cellspacing=0><tr>\n";
-
for($repeat = 1; $repeat <= $length; $repeat++)
-
{
-
$number = fgetc($file);
-
echo "<td><img src=\"$imagedir$number.gif\" alt=\"$number\">
-
\n";
-
}
-
echo "</tr></table>\n";
-
fclose($file);
-
}
-
else
-
{
-
if($debug != 0)
-
{
-
echo "Error: Could not open the file, or file does not contain a
-
valid number";
-
}
-
}
-
}
-
else
-
{
-
if($debug != 0)
-
{
-
echo "Error: Hit file does not exist, or there has been a disk failure";
-
}
-
}
-
-
?>
-
Many thanks for your help. Really appreciate it. However, i got another code that may work
<?php
session_start ();
// get current hit
$opFile = fopen ("counter.txt", "r");
$handle = fread ($opFile, filesize ("counter.txt"));
fclose ($opFile);
// if new session
if (!isset ($_SESSION['hit'])){
// set session
$_SESSION['hit'] = TRUE;
// add the hit
$handle = $handle + 1;
// print javascript
echo 'document.write("'.$handle.' Hits");';
// put new hit to db
$opFile = fopen ("counter.txt", "w");
fwrite ($opFile, $handle);
fclose ($opFile);
// else
}else{
// print only
echo 'document.write("'.$handle.' Hits");';
}
?>
then create counter.txt with number (let's say: 0) as its content... nothing more not even a single space (to make sure $handle + 1 won't produce error)
then on your html page, put:
<script language="JavaScript" src="counter.php" type="text/JavaScript"></script>
at the place where you want the counter to appear...
Would this be a better option?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chad A. Beckner |
last post by:
I am starting to work on implementing ASP.NET (using VS.NET Dev 2003) into
our current ASP 3.0 intranet setup. We have several (say 15 - 20)
"applications" that are run within our intranet, which...
|
by: dixie |
last post by:
What is the best way to implement a front end for an access database via a
web browser on a private intranet?
This is totally new ground for me. I want to allow users to enter
information into...
|
by: Frank Rosario |
last post by:
Hello all; in need of some assistance. I am currently writing some
software for our companies intranet, and I need for it to specifically
access other machines on the network's Performance...
|
by: Darko Konrad |
last post by:
hi guys,
i'm about to build an companies intranet portal and i saw on couple of pages
that there has been an intranet SK available for VS 2005 beta. In my version
of VS2005 i cannot find it any...
|
by: blackstormdragon |
last post by:
Here were our instructions:
"My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
|
by: boriq |
last post by:
Hallo,
I created a project with more that 1000 different pictures in it. The
project website is divided into more subpages. Problem is that these
pages (pictures) are not cached on local...
|
by: SoulTek |
last post by:
Hi All
I'm reposting this in the correct forum I originally thought it to be an IIS issue.
Here's the original Thread
Ok here goes.
I have inherrited a local intranet site at a company I'm...
|
by: CHealey |
last post by:
I am intranet coordinator for a large insurance company and I need some help! I'm using Immediacy to host our intranet, does anyone use immediacy?
I need a hit counter to sit on our intranet but...
|
by: james |
last post by:
WATYF <WATYF1@gmail.comwrote in
news:eb43eb6a-afaa-4e39-ac0b-850afdb6d1e4@r66g2000hsg.googlegroups.com:
It gets complicated. First, a reference:...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |