Contributed by Zach
on Jul 27, 2001 at 21:22 UTC
> CGI programming
How can I automatically determine if a link to a website in my script is broken (page doesn't exist) when the user clicks the link? If the link is broken, I want to link to a default page that explains that the link was broken.
|Answer: Can I detect a broken link in my CGI Perl script|
contributed by agent00013
I'm not sure about the CGI part of it, but for the actual checking of the link you might want to look into LWP::UserAgent and for an example of LWP::UserAgent in action, try looking here. It's a long script, but maybe it'll give you some ideas.
You may just want to let the server handle 404 errors on your side. If it's their server with the bad link, just validate your links every so often with a cron job and have somebody look over the results every so often to take out links that are permanently down. Checking every link as you click it would waste system resources and slow down your site more than necessary.
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||