Solved

perl web counter

Posted on 1998-10-07
19
315 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
  • 8
  • 5
  • 4
  • +2
19 Comments
 
LVL 3

Expert Comment

by:zhongbing
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:activegs
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<!--#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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:martinag
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Who should answer?

Martin
0
 

Author Comment

by:activegs
Comment Utility
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
Comment Utility
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
Comment Utility
2.

Martin
0
 

Author Comment

by:activegs
Comment Utility
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
Comment Utility
Thanks. It took me an hour to find the calculator and two hours to understand the instructions ;-)

Martin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now