coding a WEB COUNTER , please help :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

coding a WEB COUNTER , please help :)

Post by CMG »

Hi guys,
Could you please help someone who does not know Java, PHP, HTML etc. , yet knows his way around in MS FrontPage in makeing a hit/web counter for his website?

The counter could show in text

TOTAL HITS .......... <number of hits today>
TODAY HITS ......... <total number of hits>

Sincerely Yours,
CMG :D
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

google web counter or page counter i believe and you can find some plug and play counters:-D
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

I've tries, yet mostly they come up as already-made counters ( images ) :?
Couldn't find any simple counter that would display text, of total hits and today hits.

CMG.
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

edit
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

ok, I've found another one!
http://www.akamarketing.com/simple-hit- ... -perl.html

It uses Perl ( whatever it is ), basicly it come to creating a counter.cgi file in a cgi-bin subdirectory with this code

Code: Select all

#!/usr/bin/perl

# the path for the log file
$logpath = "count.dat";

# digits for the counter
$pad = 5;

# opens the log file for reading, will be created if none exists.
open (LOG, "$logpath");
@file = <LOG>; # an array of the file contents
close(LOG);

$count = $file[0]; # the count value is the first line in the file, i.e. $file[0]
$count++; # increments the counter value

open (LOG, ">$logpath"); # opens the log file for writing
flock(LOG, 2); # file lock set
print LOG "$count\n"; # prints out the new counter value to the file
flock(LOG, 8); # file lock unset
close(LOG);

# sets the leading zeros padding for the counter
$pad = "%.$pad"."d";
$count = sprintf($pad, $count);

# prints out the counter
print "Content-type: text/html\n\n";
print "$count";
And an simple SHTML file with this

Code: Select all

<html>
<head>
<title>Basic Hit Counter Example</title>

<style type="text/css">
p {font-family:"Century Gothic", "Sans Serif"; font-size:12pt; color:black;}
</style>
</head>

<body>
<br>
<br>
<br>
<p>You are person number
<!--#include virtual="/cgi-bin/counter.cgi" -->
to view this demo!</p>
</body>
</html>
Their demo works
http://www.design-ireland.net/design/co ... demo.shtml

Yet when I do the same, it only outputs a line
"You are person number to view this demo!"
without any numbers... what do you think might be causing it?

Thanx! :D
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I don't know perl but did you:

Code: Select all

# the path for the log file
$logpath = "count.dat";
Set the path and configure the thing correctly?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

The fact that you don't even know what Perl is means I doubt you have it installed.
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

>> Set the path and configure the thing correctly?

I copied it from the tutorial, it seems to look ok.

$logpath = "count.dat"; i.e. the "count.dat" file is in the same cgi-bin directory as the counter.cgi file.

>> The fact that you don't even know what Perl is means I doubt you have it installed.

Did I have to install it? :? Where? I've tried puting it on a server and it also won't work from there...
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Where did you put the HTML file?
As you can see it includes the perl file from the cg-bin folder when it says this line:

Code: Select all

<!--#include virtual="/cgi-bin/counter.cgi" -->
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

pilau wrote:Where did you put the HTML file?
As you can see it includes the perl file from the cg-bin folder when it says this line:

Code: Select all

<!--#include virtual="/cgi-bin/counter.cgi" -->
I have put the HTML file in the web directory, that has a cgi-bin subdirectory with the cgi file in it.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

It can be that for some reason your server don't have an access to cgi-bin.. 9don't ask me how I came up with that).

You could try putting the counter.cgi file in the same directory is the html file and remove the "/cgi-bin/" from that line.

Or try to remove that preceeding slah before the "cgi-bin" in that line, i.e. make it: "cgi-bin/counter.cgi" instaed of "/cgi-bin/counter.cgi".

That's all I can think of.
CMG
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2005 10:15 am

Post by CMG »

Same, still nothing :?
Well, guess would have to look for some other script.

C.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

i think you could have learned PHP in this time:-D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the following posts may help with information and junk

viewtopic.php?t=38546
viewtopic.php?t=32554
Post Reply