Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If I understand your original question correctly, you want to implement the page counter functionality that you had previously with PHP, using perl instead - BUT, you don't want to have to convert every existing page into a script.

I can think of two ways to do this:

1) Write a script that takes a single parameter: the name of the page. The script uses the "page" parameter to find the correct template to render and display. The "templates" here can be your original html pages, with a special template tag inserted where you want the counter to go. I would implement this using CGI::Application and HTML::Template. If you also use CGI::Application::Plugin::AutoRunmode and Apache's mod_rewrite module, you can even make the URLs look the same as before.

2) The other option is to keep your original html files, but add an IMG tag where you want the counter to be. Make the SRC attribute of this image the URL to your counter script. You can pass in different page ids via a URL parameter. You'll need to return the result as an image file, however. But you can easily find (or make) GIF files for each digit, then have your script tile the appropriate pieces together to make any number. Use something like GD to do this. And make sure to send the correct (image) header, else you'll only see a broken image link.

Having said all that, be aware that page counters are, in general, frowned upon these days - especially in shared hosting environments, as they tend to waste a lot of computer resources (database read+update per user, per click!)


In reply to Re: From php to perl + template solution by scorpio17
in thread From php to perl + template solution by Nik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found