473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Intranet Hit counter

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
Jul 7 '06 #1
2 6609
sashi
1,754 Expert 1GB
Hi there,

hope the below sample will help you to get started.. good luck my fren..

Expand|Select|Wrap|Line Numbers
  1. Note: You will need to find some digits from somehere, name them as 0.gif, 1.gif, 2.gif etc. The 
  2. counter logs hits only, there is no support for cookies or host logging in this version.
  3.  
  4. To get it to work, simpy modify the code bellow this paragraph where appropriate and upload 
  5. to your server. Then on php3 pages which you want the counter to appear, use 
  6.  
  7. <? include("script location"); ?>
  8.  
  9. <?
  10.  
  11. ///////////////////////////////////////////////////////////////////////////////////
  12. //|
  13.         $fileloc = "/home/mysite/hits.txt";
  14. //|
  15. //| Change this to the url directory containing the images, including trailing /
  16. //|
  17.         $imagedir = "http://www.mysite.com/images/";
  18. //|
  19. //| If the counter is broken, or there is a problem, it will display nothing unless you set this to 1
  20. //|
  21.         $debug = 0;
  22. //|_________________________________________________________________________
  23. ________
  24. ////////////////////////////////////////////////////////////////////////////////////
  25.  
  26.  
  27. if(is_file($fileloc))
  28. {
  29.         if($hits = file($fileloc) AND $file = fopen($fileloc, "w"))
  30.         {
  31.                 $hits = trim($hits[0]) + 1;
  32.                 fputs($file, $hits);
  33.                 $length = strlen($hits);
  34.                 fclose($file);
  35.                 $file = fopen($fileloc, "r");
  36.                 echo "<table cellspacing=0><tr>\n";
  37.                 for($repeat = 1; $repeat <= $length; $repeat++)
  38.                 {
  39.                         $number = fgetc($file);
  40.                         echo "<td><img src=\"$imagedir$number.gif\" alt=\"$number\">
  41. \n";
  42.                 }
  43.                 echo "</tr></table>\n";
  44.                 fclose($file);
  45.         }
  46.         else
  47.         {
  48.                 if($debug != 0)
  49.                 {
  50.                         echo "Error: Could not open the file, or file does not contain a 
  51. valid number";
  52.                 }
  53.         }
  54. }
  55. else
  56. {
  57.         if($debug != 0)
  58.         {
  59.                 echo "Error: Hit file does not exist, or there has been a disk failure";
  60.         }
  61. }
  62.  
  63. ?>
  64.  
Jul 7 '06 #2
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?
Jul 14 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
14
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...
0
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...
4
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...
3
blackstormdragon
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...
6
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...
1
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...
0
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...
3
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:...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
1
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...
1
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....
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.