Forum Moderators: coopster
Many of them just put a bogus domain in reciprocal field, (they simulate being linking to me but that domain is not the same where they want a link back)
I need a script that detects that, BEFORE they submit, and STOP the submission if that is incorrect.
IE: Correct form
url: [thewebsitewheretheywantalinkfrom.me...]
reciprocal_url:
[thewebsitewheretheywantalinkfrom.me...]
IE: Incorrect and must be stopped:
url: [thewebsitewheretheywantalinkfrom.me...]
reciprocal_url: [abogusurl...]
May you suggest some php lines to add to my form?
If it's not the right form of url you have a couple options:
1. Have your script fix the mistake. ie. if there are two http's as in your example, you can just use something like str_replace (this is a php example) or preg_replace to get rid of erroneous extra stuff like that. Google for a link validation regular expression.
2. Send back an error without further processing if it;s the wrong form of url. You would also need regex for this vlaidation.
Learn/search for regex stuff. Have fun :)
9.4 HEAD
The HEAD method is identical to GET except that the server MUST NOT
return a message-body in the response. The metainformation contained
in the HTTP headers in response to a HEAD request SHOULD be identical
to the information sent in response to a GET request. This method can
be used for obtaining metainformation about the entity implied by the
request without transferring the entity-body itself. This method is
often used for testing hypertext links for validity, accessibility,
and recent modification.
... which seems to lend itself nicely for the problem you are addressing. So what you need to do is open a socket to the intended target and issue a HEAD request. Then read the response for a positive status.
Here is a quick example to get you started ...
<pre>
<?php
$target = 'www.example.com';
$page = '/path/to/page.htm';
$fp = fsockopen($target, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)";
} else {
$out = "HEAD $page HTTP/1.1\r\n";
$out .= "Host: $target\r\n";
$out .= "Connection: close\r\n\r\n";
fwrite($fp, $out);
$response = '';
while (!feof($fp)) {
$response .= fgets($fp);
}
fclose($fp);
print $response;
if (preg_match("/200 OK/", $response)) {
print 'good target';
} else {
print 'bad target';
}
}
</pre>
>?