Do you have a big list of links in your database that you want to display but only want to show ones that are still in existance? Well theres a very easy method for doing so. All you need is the fsockopen() function. Here is an example:
| <? $testURL = @fsockopen("www.FreeTemplateDesigns.com", 80, $errno, $errstr, 30); if($testURL) { echo "<a href="http://www.FreeTemplateDesigns.com">Free Template Designs</a>"; } >?> |
In this example you can see the fsocketopen() function being called as a test on the url. If it can connect to it, it exists and prints. Otherwise, nothing happens. now lets say you wanted to do this with a large list of links from your database. It's just as simple.
| <?php $link = mysql_connect('localhost', 'username', 'password'); mysql_select_db('database', $link); $query = mysql_query("SELECT * FROM links"); while($row = mysql_fetch_array($query)) { $testURL = @fsockopen("www.FreeTemplateDesigns.com", 80, $errno, $errstr, 30); if($testURL) { echo "<a href="http://$row[url]">$row[name]</a><br>"; } } ?> |


Reply
Reply
Reply
Reply
Reply
Reply
abaysimple_1991@yahoo.com
Reply
Reply
iamnekko@yahoo.com
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Read more: http://www.webdesign.org/web-programming/php/url-verification.6852.html#ixzz1HV0mnzLL
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Read more: http://www.webdesign.org/web-programming/php/url-verification.6852.html#ixzz18TnKTALm
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Reply
This works good but will only do one part of the job. If someone needs to test if his backlink on a specific page still exists, you need to use some regulare expression like:
[code]
if (preg_match("/<a(.*)href=["']http://www.domain.com(/?)["'](.*)>(.*)</a>/", $part)) {
$var = true;
}
Check the whole function here: (Back) link checker
Regards Olaf
Reply