Part II of Customized borders and corners has just been handed over the editors at A List Apart, and should hopefully be published soon.

In the meantime, here's a nice little ASP function I wrote with help from David S. I use this in my comment system. When someone writes a comment and gives his websites URL, it checks whether the website in question has a favicon.ico or not - and if it has, the favicon is displayed next to the users name.

<% 	
Function HttpExists(uri)
Dim srvXmlHttp
Set srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
srvXmlHttp.setTimeouts 500, 500, 500, 500
srvXmlHttp.open "HEAD", uri, false
on error resume next

srvXmlHttp.send
If Err.Number = 0 Then
	If srvXmlHttp.Status=200 Then
	HttpExists=True
	else
	HttpExists=False
	end if
	else
	HttpExists=False
end if
End Function
'  ********************
' Now feed the function with an URL, like:
' domain = cmd("url")
domain = "http://www.picment.com"

 ' Make sure there is a trailing slash
If Right(domain, 1) <> "/" Then
domain = domain & "/"
End If

url2chk = domain & "favicon.ico"

If HttpExists(url2chk) then
Response.Write " "
' else 
' Response.Write url2chk & " could not be found"
end if
%>

You should probably cache this information in a database, if you have alot of URL´s to check, since it will slow your page processing down considerably. I´m very open to suggestions on how to improve this.

Try it out! Leave a comment. Oh — and a merry christmas to you all :)

Update:
This little function now has it's own article, Favicon pinger with classic ASP/VBScript

Comments:

Jeppe wrote: Sunday, December 28, 2003 | 18:19 (GMT +01.00)
just a taste, bud!


Sean wrote: Sunday, January 04, 2004 | 10:56 (GMT +01.00)
Nicely done. Thanks!


deadlock wrote: Friday, January 23, 2004 | 17:09 (GMT +01.00)
Now this is something nice and original!
Great work!


Craig Jardine wrote: Wednesday, February 25, 2004 | 10:36 (GMT +01.00)
Testing...1...2...3

Nice Articles!


Jacob Herman wrote: Saturday, February 28, 2004 | 00:00 (GMT +01.00)
Cool, is there a php version of this?


aol user wrote: Saturday, February 28, 2004 | 00:34 (GMT +01.00)
hi


Asparagirl wrote: Sunday, February 29, 2004 | 23:16 (GMT +01.00)
Testing testing, 123...


OCB wrote: Tuesday, March 02, 2004 | 11:22 (GMT +01.00)
V-PHP (not tested but should work...)


function remote_file_exists ($url)
{
$head = "";
$url_p = parse_url ($url);

if (isset ($url_p["host"]))
{ $host = $url_p["host"]; }
else
{ return false; }

if (isset ($url_p["path"]))
{ $path = $url_p["path"]; }
else
{ $path = ""; }

$fp = fsockopen ($host, 80, $errno, $errstr, 20);
if (!$fp)
{ return false; }
else
{
fputs($fp, "HEAD ".$url." HTTP/1.1\r\n");
fputs($fp, "HOST: dummy\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while (!feof ($fp))
{ $headers .= fgets ($fp, 128); }
}
fclose ($fp);
$arr_headers = explode("\n", $headers);
$return = false;
if (isset ($arr_headers[0]))
{ $return = strpos($arr_headers[0], "404") !== false; }
return $return;
}

// usage

$url2chk = "http://www.zeldman.com/favicon.ico";
if (remote_file_exists ($url2chk))
{ print ('<img src="' . $url2chk . '" alt="Icon" />'); }
else
{ print ($url . " could not be found"); }


Søren Madsen wrote: Tuesday, March 02, 2004 | 11:59 (GMT +01.00)
Oh - very nice OCB!


Jacob Herman wrote: Wednesday, March 03, 2004 | 01:23 (GMT +01.00)
OCB, I copied this and tried to execute it. Even though we both know that the favicon.ico exists at zeldman.com, it still said "could not be found." I'm working on a way to do this, I'll post it when I'm done with it.


Clandestino wrote: Wednesday, March 03, 2004 | 09:52 (GMT +01.00)
Good one!


Jacob Piil wrote: Tuesday, March 16, 2004 | 08:31 (GMT +01.00)
OK copied it and tried to execute it. Even used your http://www.picment.com as domain and nothing comes up. Then I remove the ' for your else condition is says: http://www.picment.com/favicon.ico could not be found


Rob wrote: Tuesday, May 25, 2004 | 14:57 (GMT +01.00)
If remote open wrappers are enabled, the PHP becomes much simpler:

<?php

// Check if domain ends in trailing slash
$domain = (substr($_POST['domain'], -1) == '/') ? $_POST['domain'] : $_POST['domain'].'/';

// Check if the favicon exists
if(file_exists($domain.'favicon.ico')) {

// Display the favicon
echo '<img src="'.$domain.'favicon.ico" alt="Icon for '.$domain.'" title="Icon for '.$domain.'" />';

}

// Favicon doesn't exist/URL is wrong; display error message
else {

echo ''.$domain.' either could not be found or does not have a favicon.';

}

?>


chartoo wrote: Sunday, June 27, 2004 | 04:09 (GMT +01.00)
I'm going to have to try this on my site.
;-)


Hans wrote: Thursday, September 30, 2004 | 10:35 (GMT +01.00)
Kickass script, thx for sharing!


Rob Lewis wrote: Saturday, November 06, 2004 | 12:12 (GMT +01.00)
Nice idea for a script! Let's see if it works...


Jeppe wrote: Sunday, July 03, 2005 | 12:45 (GMT +01.00)
why doesnt it work anymore?
snedker.netuni.dk/favicon.ico IS a valid URL! and there is no favicons in the comment postings anymore


Craig Munro wrote: Wednesday, July 06, 2005 | 10:32 (GMT +01.00)
Thanks for the script - it works really well the majority of the time! There is one error I've noticed though:

If the webserver you're requesting the file from has custom 404's in the form of a page redirect, the script gets mighty confused, and tries to load the 404 page as an image. For example:

http://www.sober-productions.co.uk/favicon.ico Doesn't exist, so the server returns the custom error page (which is then returned correctly, giving the script a response code of 200 to deal with). The script then tries to load the error page as the image. Do'h!

Does that make sense? I'm sure there's some way around it, but I'm too frazzled to try and work it out :)


Sentel wrote: Saturday, July 09, 2005 | 16:43 (GMT +01.00)
Nice feature!

just testing


Jef Gustafsson wrote: Monday, August 29, 2005 | 09:06 (GMT +01.00)
Great idea *


Sorry - comments have been turned off

I have not been able to find a robust solution to the massive amount of comment spam I have been experiencing. I have tried filtering the entries for obvious spam content - but that hasn't helped much, since the spammers apparently has registered this, and are now hitting me with all sort of generic words.

If anyone has a solution to this incredibly annoying madness - by all means, contact me.