So I spent some time in developing a php function that allows me to validate the existence of a text in a given URL (if any).
Code:
<? Php
validaLinkReciproco function ($ feedURL, $ searchString) {
/ * Used to validate the reciprocal link.
Who use this script, probably by an include
Returns: true (string found), false (string not found) * /
/ / First check if curl is installed on the web server.
$ CurlInstalled = true;
if (! extension_loaded ('curl')) {
if ( strtoupper ( substr (PHP_OS, 0, 3)) === 'WIN') {
if (! dl ('php_curl.dll')) {/ / Attempt to load the extension for Windows systems
$ CurlInstalled = false;
Else {}
$ CurlInstalled = true;
}
Else {}
if (! dl ('curl.so')) {/ / Attempt to load the extension for POSIX systems
$ CurlInstalled = false;
Else {}
$ CurlInstalled = true;
}
}
}
/ / Depending on whether you installed curl, we obtain the data one way or another
if ($ curlInstalled == true) {
/ / Retrieve data from curl
$ OhYeah = curl_init ();
curl_setopt ($ OhYeah, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ OhYeah, CURLOPT_URL, $ feedURL);
$ Err = curl_error ($ OhYeah)
$ Pagedata = curl_exec ($ OhYeah)
curl_close ($ OhYeah)
Else {}
$ Pagedata = file_get_contents ($ feedURL);
}
/ / Find the string in the string
$ Pos = strpos ($ pagedata, $ searchString);
if ($ pos === false) {
/ / String $ searchString $ feedURL not found in
return false;
}
else {
/ / String $ searchString $ feedURL found in
return true;
}
}
?>;
This is obviously a function that should be used in the paragraph to validate the data submitted by the form, where $ feedURL, should contain the URL where you want to search (in our case given by the reciprocal link URL field - see the image above). The function returns true or false, depending on who is the search string in the HTML of the page listed for $ feedURL.
Bookmarks