Gossamer Forum
Quote Reply
Modification to URL
I need to make a modification to a URL when the URL contains a certain string. For example I might want to change a link which contains yahoo.com to a totally different link encompassing that url... so, when a person clicks on a link which executes jump.cgi a link to:

http://yahoo.com/

Would take the person instead to:

http://www.genealogysurnames.com/url.cgi?Uhttp://yahoo.com/

I would like to do this on the fly without actually changing the data in the database itself. Can this be done using a global? And if so, are there any perl gurus who could help me get the global started???

Thanks!
Dennis
http://www.genealogysurnames.com/

Last edited by:

perdrix: Jul 3, 2002, 10:21 AM
Quote Reply
Re: [perdrix] Modification to URL In reply to
I would recommend the following:

1) Create another table called Links_Check_Words:

Quote:

CheckWordID (PRI, AUTO-INCREMENT, NOT Null, INDEX)
CheckWords (TEXT, NOT Null. INDEX, NOT UNIQUE)
Add_CheckWords (DATE, NOT Null)
Mod_CheckWords (DATE, NOT Null)


2) Then in your add.cgi script, you'll need to add a query of the above table, with the following SQL statement:

Quote:


my $url = $IN->param('URL');

SELECT LCW.CheckWords
FROM Links_Check_Words LCW
WHERE (LCW.CheckWords = '$url')


3) Then if a match is found in the table, you could UPDATE a column in the Links table called something like isChange (ENUM, Yes/No, Not Null, Default = No).


4) Then in the jump.cgi script, you'd have to add a hook to check for the isChange column and if that column equals "Yes", then it would redirect the URL example you posted.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [perdrix] Modification to URL In reply to
It's quite simple really.

Just add a new field called URL2 in your database and then in Links/User/Jump.pm change:


$goto = $rec->{URL};

to


$goto = $rec->{URL2} || $rec->{URL};

...thats the easiest way to do it.
Quote Reply
Re: [Stealth] Modification to URL In reply to
Thanks Stealth for replying. I read your instructions and code and though I believe I might be able to eventually initiate what you suggested, I also think I would probably be battering my head up against the computer all day as I make one mistake after another... Pirate

I will choose suggestion #2 solely due to it's simplicity. Thanks for replying though.

Dennis
Dennis
http://www.genealogysurnames.com/
Quote Reply
Re: [Paul] Modification to URL In reply to
Hi Paul,

Thanks for the simple solution. One problem still remains after initiating your suggestion though. That is filling in the new column with the required new url. Though I could easily export the information and then modify it offline and get it to do what I want, is there a way to run a MySQLMan query and automatically populate the column with the information I need to insert into it?

Using MySQLMan I can search for the url within the url field and get the results I want. It would seem likely then that there is a method of automatically inputting the information I want into it. Remembering the fact that I would need to automatically input the new redirect and URL into the URL2 column at the very end of the code only in instances which match %yahoo.com%.

Can anyone provide the syntax neccessary for that action?

Thanks!
Dennis
http://www.genealogysurnames.com/
Quote Reply
Re: [perdrix] Modification to URL In reply to
UPDATE Links SET URL2 = 'http://bla...' WHERE URL LIKE 'http://www.yahoo.com%'

Last edited by:

Paul: Jul 4, 2002, 10:02 AM
Quote Reply
Re: [Paul] Modification to URL In reply to
Hi Paul,

This works minus one step and with one alteration. The alteration I figured out easily enough and that was the fact that all of my tables are prepended with "lsql_"

The problem I am going to encounter however is that your example does not insert the original url info into the end of field URL2. I use a redirect and then the actual URL of the page. So http://www.yahoo.com/blah would have to be inserted into:

URL2 = 'http://bla...'

Is that possible to do? I was able to easily alter the file offline but have been unable to get MySQLMan to import the whole thing without returning a server error at some point during the large file import.

Dennis
Dennis
http://www.genealogysurnames.com/
Quote Reply
Re: [perdrix] Modification to URL In reply to
Uh...those were not separate solutions, it was combined as a step-by-step suggestion.

best of luck finding a solution...
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Modification to URL In reply to
I think he was referring to my suggestion as #2
Quote Reply
Re: [Paul] Modification to URL In reply to
Really? Cause he replied to me...in that post.
========================================
Buh Bye!

Cheers,
Me