Well i had the basic idea a few days ago but Ken helped me out mostly. Its just a small thing. If you want it here it is.
change :
Code:
# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {
to:
Code:
# Validate the form input..
$status = &validate_record(%in);
my %ok_status = (
200, "OK 200",
201, "CREATED 201",
202, "Accepted 202",
203, "Partial Information 203",
204, "No Response 204",
);
my ($status2, $error) = &check_link ($in{'URL'});
if (!exists $ok_status{$status2}) {
$error =~ /\s(.*)/;
$status2 = "<ul><li>URL ($1) : <b>$status2</b></ul>";
($status eq "ok") ? $status = $status2 : $status .= $status2;
}
if ($status eq "ok") {
then at the very bottom, put this
Code:
sub check_link {
# -----------------------------------------------------
# Check links without LWP.
#
my ($url) = shift;
my ($host, $port, $path, $sock, $line);
($url =~ m,^http://([^:/]+):?(\d*)(.*),i) and (($host, $port, $path) = ($1, $2, $3));
$path | |= '/';
$port | |= 80;
$path =~ s/#.*//;
$host or return undef, "Can't parse host from url: $url";
use IO::Socket;
$sock = new IO::Socket::INET ( PeerAddr => $host,
PeerPort => 80,
Proto => 'tcp',
Type => SOCK_STREAM ) or return undef, $@;
print $sock "HEAD $path HTTP/1.0\n";
print $sock "User-Agent: LookHard UrlScope(http://www.lh.yi.org)\n\n";
my $response = <$sock>;
(my $protocol, $status) = split / /, $response;
while (defined ($line = <$sock> )) { }
close ($sock);
return $status;
}
which is the same thing from verify links. So see what this does is when you submit, it checks the hostname a la Yahoo. If it exists, it continues with the rest of the script, if it comes up with an error it will not finish the script. Oh, the : $status2 <ul><li>URL ($1) -> : <b>$status2</b><- </ul> part can be removed. I only put that so link adders could get a better idea. I'm gonna make mine display the actual code text. Oh and if you want your own thing to show up in the users logs you can change my UrlScope thing to your name or whatever i guess. The coolest thing about this is it shows its own errors, like say a user doesn't even submit an Url. It will show the old links Url can not be left blank, but also Url not parsed which is from my thing. And if the hostname or url is a fake, it shows Host not parsed or found or something. Thanks alot Ken.
If you want to try it go here
http://www.lh.yi.org/cgi-shl/look/addurl ------------------
------------------------------------------
Lavon Russell
LookHard! Search
www.lh.yi.org webmaster@lh.yi.org [This message has been edited by Bmxer (edited August 06, 1999).]
[This message has been edited by Bmxer (edited August 07, 1999).]