Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Add verify

Quote Reply
Add verify
If i wanted to make the add.cgi file look for the url specified and then if its found it will keep parsing the script and data but if its not found it goes straight to the error page. If so, would it look like this

Code:
use LWP::Simple;



if (head($in{'URL'})) {
# ok document exists
}
I wanna make the ones that get the 200 code to be put in the valid.db file and the others, well they won't show up, sort of like Yahoo. I figure i can do this with an else call at the end but i'm not sure where to put it. Inside sub main or sub process form?

------------------
------------------------------------------
Lavon Russell
LookHard! Search
http://www.lh.yi.org
webmaster@lh.yi.org
Quote Reply
Re: Add verify In reply to
That's a great idea Bmxer. It's amazing how many people can't type their own URL correctly. You'd probably get faster help if you put it in the mods forum though.
Quote Reply
Re: Add verify In reply to
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).]
Quote Reply
Re: Add verify In reply to
I also changed something so that you can block certain domains from being added, such as businesses like microsoft or quicken. This and the other mod help in your validating time. I still have not figured out how to check the redirected url of like come.to. It shows a 302 if someone with that url adds. So they can't add, but i know this thing can redirect so i'm trying to get it.

------------------
------------------------------------------
Lavon Russell
LookHard! Search
http://www.lh.yi.org
webmaster@lh.yi.org