PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP URL Verification
Your Ad Here

URL Verification


URL VerificationDo 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>";
}
}
?>


Author's URL: Andrew Spiziri
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "URL Verification"

Only registered users can write comment

Reader's comments
comments olaf December 31, 2005 says:
URL Verification
Hello,

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("/(.*)/", $part)) {
$var = true;
}


Check the whole function here: (Back) link checker

Regards Olaf