Solved

perl web counter

Posted on 1998-10-07
19
325 Views
Last Modified: 2008-02-26
Hi ppl,

just wondering how to run a perl script in the background, say for a web counter.

for instance, if I have index.html is there a way i can open a data file, get the current value, add one to it and close the file with the viewing noticing anything?

like the way counters display an image via a script that does the same, except i dont want to do anything the user can see....
0
Comment
Question by:activegs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
  • +2
19 Comments
 
LVL 3

Expert Comment

by:zhongbing
ID: 1205187
you can use you perl cgi as the page. and cat the index.html in the perl file. just like this:

system("cat image.html");

so you can let the image.html and the counter appers in one page.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1205188
Assuming your operating system has a `cat` command..

You may also want to lock the file so two users trying to change the current value at the same time don't clash.
0
 

Author Comment

by:activegs
ID: 1205189
My system does not have a cat command, I am running NT.

I think the answer lies in HTML syntax wouldn't you think? Not in the perl script itself.

<img src=counter.pl> : this html prompts the browser to get an image/jpg or image/gif generated by a perl script, but the user cannot see the script in action (apart from the generated image). I want the HTML that prompts the browser to run a perl script without having any effect on the user (to simply update a file for my benefit).

ta
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:activegs
ID: 1205190
Plus also, if i were to use a perl file to write the contents of index.html then if someone typed : www.ActiveGS.com.au/ (my website :))
then index.html would be the default (not index.pl) thus I would lose hit counts.

thnaks again

0
 

Expert Comment

by:mazares
ID: 1205191
Here's how I do mine. The html document needs to have a line like this to execute the counter when the document is retrieved:

<!--#exec cgi="/teima/cgi/mycount.cgi"-->

Then, here's the script it executes. As per your request, it opens, read froms, and increments a count number contained in a data file:

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
#============================================================
#                        MYCOUNT.CGI
#============================================================

    $File1 = "+</usr/local/www/data/teima/dat/.mycount";
    $LogRec = "A6";
    open (COUNTFILE, $File1);

    seek(COUNTFILE, 0, 0);
    $buf = read(COUNTFILE, $rec, 6);
    ($num) = unpack($LogRec, $rec);

    $num = $rec + 1;
    seek(COUNTFILE, 0, 0);
    print COUNTFILE pack($LogRec, $num);
    close(COUNTFILE);

    print "<!-- ", $num, " -->\n";

This counter is invisible to the viewer of the html page. You can make it visible by doing something like this for that last line:

print "Yours is visit number", $num, "to our site.\n";

Hope this helps.

0
 

Expert Comment

by:mazares
ID: 1205192
Forgot to mention -- you can go see where that script I suggested is used: www.vdospk.com/teima/myweb.htm  Since it's invisible to the user, you have to use your viewer's "view source" function to see the counter number embedded in the code.
0
 

Author Comment

by:activegs
ID: 1205193
<!--#exec cgi="/teima/cgi/mycount.cgi"-->

is an ssi capability isn't it? if i do not have server side includes (my isp doesn't) how can i do this type of thing - or can i?
0
 

Expert Comment

by:mazares
ID: 1205194
Geez, activegs, I may not be smart enough to answer that one... I'd say, just try it. I know my isp is about as antiquated as they come, and it works on their machine. Try it and let me know.
0
 

Author Comment

by:activegs
ID: 1205195
it didnt work....however i am wondering if pluging the script into an image that when drawn was 1x1 pixels.

like <img src=perlsc.pl> and it did all the stuff i wanted plus returned a 1x1 image.

could work - might try it.

thanks....anyother suggestions?

0
 
LVL 4

Expert Comment

by:martinag
ID: 1205196
You could output the whole HTML from an .pl using content-type: text/html and reading the file in, add the counter at a special location and print the result out...
You want code?

Martin
0
 

Author Comment

by:activegs
ID: 1205197
That is definately an option, but as i think i stated earlier, index.html is the default file to load when no file is specified (meaning that if i depend on index.pl (or whatever) to do the counting, then I will lose hit counts when someone types http://www.ActiveGS.com.au/ rather than http://www.ActiveGS.com.au/index.pl
unless there is a way i can force index.pl to be loaded all the time (on every browser - not just ones that support redirection) then maybe that idea is not real good.

any other suggestions?
0
 
LVL 4

Expert Comment

by:martinag
ID: 1205198
Well, most browsers (99.9% or something like that I guess) supports redirecting.

If you want to set index.pl as default, it's rather easy on most servers. I don't know about NT, but such thing should be easy to do.
Either you could just change the setting for the top directory to index.pl, but not for the other. Or you can make index.* default (I think you can use *'s) in all directories.

There is another solution...Have index.html load a frameset with index.pl plus a hidden frame. Then, all links from index.pl loads into the whole browser (TARGET="_top").
But then of course, the browser has to support frames (Again, 99.9% I think).

Martin
0
 

Author Comment

by:activegs
ID: 1205199
I dont know about 99 percent supporting frames, but redirection is common - i have decided to go with the image idea i came up with, it works ok. thanks for all your help, I have no probs handing over the points for all the time you spent. thanks again

email me at John@ActiveGS.com.au for future discussions/help/questions etc.

if you answer the question, i give points

john
0
 
LVL 4

Expert Comment

by:martinag
ID: 1205200
Who should answer?

Martin
0
 

Author Comment

by:activegs
ID: 1205201
Uh geez, tough one....all I can really do is ask another question... OK What is 1 + 1 equal to? The first one to answer this gets the points.

:)John
0
 

Expert Comment

by:mazares
ID: 1205202
This one really puzzles me... the script I offered earlier, and the "exec cgi" call that executes it, have worked great for me on a lot of different sites. I don't really understand why it wouldn't work for activegs. I trust he changed my literal path and filenames to match those he's actually using.
0
 
LVL 4

Accepted Solution

by:
martinag earned 50 total points
ID: 1205203
2.

Martin
0
 

Author Comment

by:activegs
ID: 1205204
mazares, The script doesnot even execute, some servers do not allow for SSI (server side includes) mine is one of them (Generally NT boxes) exec is an SSI command - it would be the way to go if I did have ssi, but I dont. Thanks again.


By the way, Martinag, brilliant answer.:)
0
 
LVL 4

Expert Comment

by:martinag
ID: 1205205
Thanks. It took me an hour to find the calculator and two hours to understand the instructions ;-)

Martin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question