473,322 Members | 1,473 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,322 software developers and data experts.

Need help with a counter

What I have is this php code saved as a .php file
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $count_my_page = ("hitcounter.txt");
  3. $hits = file($count_my_page);
  4. $hits[0] ++;
  5. $fp = fopen($count_my_page , "w");
  6. fputs($fp , "$hits[0]");
  7. fclose($fp);
  8. ?>
And this in my html code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include ("counter.php");
  3. ?>
I have never done any webdesign before so I am stumped on how to get this to work. I got the code from some website, what I need is I have a server that does html, no asp or anything, and I need an invisible counter on the page that writes the hit count to a txt file. Any help would be appreciated, THANKS!!
Jun 21 '07 #1
2 1237
rnd me
427 Expert 256MB
I have a server that does html, no asp or anything,
PHP won't do anything for you in that case.

assuming you can assign write access to a folder or file, you can use the client to do this via AJAX. this is not the most reliable process in the world, but it sure beats nothing.

here is the simplest thing i could think of:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function IO(U, V) {
  3. X = !!window.XMLHttpRequest ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;
  4. X.open(V ? "PUT" : "GET", U, !!0);
  5. X.send(V ? V : "");
  6. return X.responseText;}
  7. var oD=IO('hit.txt');
  8. IO('hit.txt', oD+'.')
  9. </script>
  10.  
  11.  
the filesize of hit.txt = the number of hits.
Jun 21 '07 #2
pbmods
5,821 Expert 4TB
Heya, tehgreatmg.

If your server has PHP installed, rename your page to have a .php extension and add the include statement at the top of your script.

For example, if your page were called 'home.html', you'd rename it to 'home.php' and add the following code to the top of the page:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include ("counter.php");
  3. ?>
  4.  
On the other hand, if (as you mentioned in your OP) you can't use anything other than HTML, you'll have to use an external script to update your hit counter. http://www.google.com/search?q=hit%20counters
Jun 21 '07 #3

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

Similar topics

15
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example :...
7
by: brian.digipimp | last post by:
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd...
3
by: moondaddy | last post by:
I have some text in a page that when a certain even happens, I need to make it glow from black to red (through a spand of 1 second) pause for a few seconds, and then slowly change from red to black...
6
by: Glenn Wilson | last post by:
I have converted most of the code that I have but am having trouble, mainly with the marked lines. (>>) public static UInt16 checksum( UInt16 buffer, int size ) { Int32 cksum = 0; int counter;...
8
by: bmlclemson08 | last post by:
Hey if anyone could I need to find out how to write a program that will read in any number of integers, including none, and determine which is the largest integer. The part i can't figure out is...
13
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else...
0
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
0
by: yjh0914 | last post by:
hi guys! so im basically editting my post i made earlier as it wznt as specific.. i have to make a program that basically ranks students by their cumulative gpa. the student's info is on a csv file...
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...
1
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.