CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
verifying url's

 



Aquilo
journeyman

Dec 18, 2000, 4:37 PM

Post #1 of 4 (587 views)
verifying url's Can't Post

How do I tell a script to verify that a url is valid??

Thanks



Rivotti
User

Dec 18, 2000, 5:24 PM

Post #2 of 4 (584 views)
Re: verifying url's [In reply to] Can't Post

Hi Aquilo,

You must use a regular expression

if($url =~ /^www\.[\w\-\.]*\.[A-Za-z][A-Za-z]+/i) {
## do something if true
}
else {
## do something if not
}

What means $url =~ /^www\.[\w\-\.]*\.[A-Za-z][A-Za-z]+/i ?

/^www. # string begins with www.
[\w\-\.]* # followed by a letter (\w) or a - or a ., none or more times (*)
\. # followed by .
[A-Za-z] # followed by a letter
[A-Za-z]+ # followed by a letter, one or more times (+)

I hope I helped
Rivotti




japhy
Enthusiast

Dec 18, 2000, 9:01 PM

Post #3 of 4 (578 views)
Re: verifying url's [In reply to] Can't Post

Well, the easiest way to check if a URL you're given is valid is to try and fetch the headers from it:


Code
use LWP::Simple 'head'; 
$url = "http://www.perlguru.com/";
$valid = head $url;

If $valid is false, the URL isn't valid.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


Aquilo
journeyman

Feb 28, 2001, 3:38 PM

Post #4 of 4 (551 views)
Re: verifying url's [In reply to] Can't Post

it's been a long time since i started thinking of this script :)
japhy? what do I with $valid or what is the systems responce if the "head $url" is valid or false?

what I'm doing is seeing if subdomains are used on
one of my free webspace communities, so would/should

Code
use LWP::Simple 'head'; 
$url = "http://www.perlguru.com/";
$valid = head $url;

just return the header of www.perlguru.com like $url=get("http://www.perlguru.com"); only not the hole page :)

I don't know what the headers of valid urls will be but I do know what a false one will be!
and I need to tell the script what sub to use for valid or invalid


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives