Gossamer Forum
Home : General : Perl Programming :

link/result-page problem. Help please!!

Quote Reply
link/result-page problem. Help please!!
I have yet another problem. I'm new to perl, so if you all could bare with me and help me out I would appreciate it. :)

So I have a table with a column full of regular <a> HTML link tabs, each referencing to a different website. So what I'd like to do is the following:

Once the user clicks on one of the links, I'd like to take the source code of the resulting page make a few changes and then display the new page with the slightly different source code.

I figured out how to retreive a source code,and i definately know how to make changes to it using regular expressions. But I don't know how to go around doing the described above. I hope it's clear. I'm not sure whether it's a perl or HTML problem.

Thank you soooo much!
Quote Reply
Re: [q8tygirl] link/result-page problem. Help please!! In reply to
Hi. You need to structure it something like;

script.cgi > SELECT * FROM TABLE LIMIT 10
script.cgi?nh=2 > SELECT * FROM TABLE LIMIT 20,10
script.cgi?nh=3 > SELECT * FROM TABLE LIMIT 30,10

I use something similar in my scripts to work out the offset;

if ($page == 1) {
$start = $page * $per_page - $per_page + 1; # i.e page 1 * 5 - 5 = 0
$end = $page * $per_page; # i.e page 1 * 5 + 1 = 6
} else {
$start = $page * $per_page - ($per_page - 1); # i.e page 2, 2 * 5 - (5 - 1) =
$end = $page * $per_page; # i.e page 2 * 5 = 5

Its far from perfect, but it seems to do the job.

(its a lot simpler if you are doing a nice easy amount per page, i.e 10. Its when you start doing stuff like 15,25, etc, that it is a little more complex).

Hope that helps.


Andy (mod)
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] link/result-page problem. Help please!! In reply to
Thanks alot for the reply Andy. But I think you might have misunderstood what kind of a table I was talking about.

This is what I have: A website with an HTML table. In that table there's a column of different links. Each link is referencing to a completely different website.

What I want to do now is the following: Depending of what link the user presses on, I take the location of the website he chose. I retreive the source code (I know how to retreive the source code given the link). Change the source code a little ( I know how to do that too). And then display to the user the newer version of reference link he chose.

So what I really need to know how to do is, know the link the user is gonna press on, take it, make changes, and display the new link to the user instead of the old one. I'm thinking this is an HTML question more than perl. However, I am using perl as a programming language here, so I thought I'd post the question in the forum. :)

Thanks again! :)
Quote Reply
Re: [q8tygirl] link/result-page problem. Help please!! In reply to
Hey there,

I can think of a few ways to do this but the resulting URL in the browser's location bar will never show the URL of the original page. Rather, it would have to show the location of your script or a dummy page of your choosing which would call the Perl scrpt via SSI.

I assume you are using LWP::UserAgent to fetch the code of the target page?

To display the modified content (let's say your modified complete page code resides in a variable named $modifiedContent), you just need to end your script (or subroutine) with this:

if you are using CGI.pm (let's say your query is in $q):
print $q->header, $modifiedContent;

or if you are not:
print "Content-type:text/html\n\n";
print $modifiedContent;

The links in your table would need to point to your Perl script and have the target URL as a parameter.

Alternatively (if like me you prefer not having your cgi-bin path in the URL), you can direct the links to a dummy file, again using the target link as a parameter.
Your dummy file would just contain an SSI directive calling your script with the parameter passed to the file, like so:
<!--#include virtual="/cgi-bin/codemodifierscript.pl?$QUERY_STRING"-->
This works beautifuly with Apache. I have had issues with IIS however.

Hope this helps, let me know.
Quote Reply
Re: [Crolguvar] link/result-page problem. Help please!! In reply to
Thanks, it did! :)