Add gravatar to your ASP site
- By: Qwaider
- On:Sunday, May 28, 2006 4:30:14 PM
- In:Science & Technology
- Viewed: (9530) times
- Currently 4.6/5 Stars.
- 1
- 2
- 3
- 4
- 5
Rated 4.6/5 stars (244 votes cast)
Some great guy once said, if you solve a tough problem, Blog it. It will help the next guy struggling with it. Since this got me scratching my head for couple of hours, I decided to spare the next guy struggling with it.
The reason I'm doing this is simple, to the best of my knowledge, no one has done it for ASP.
So ... lets start at the top.... .What is gravatar? From their website http://www.gravatar.com/, I got the following explanation
What is a gravatar?
A gravatar, or globally recognized avatar, is quite simply an 8080 pixel avatar image that follows you from weblog to weblog appearing beside your name when you comment on gravatar enabled sites. Avatars help identify your posts on web forums, so why not on weblogs?
Think of gravatar.com as a dictionary that associates email addresses and avatar images. When you leave a comment on a weblog and provide your email address, the weblog can use your email address to look up your avatar. Since the dictionary is available to anyone, a single avatar image can represent you across many different weblogs.
Now also from their site, in the FAQ section, they state that you will need to send them the email address of the user to receive their Gravatar image. Which poses a serious problem: How do you do that, without getting people spammed senseless? The answer was simple enough. Use a one way hash (in their case MD5) to generate the equivalent of the Email address.
Now I don't want to get into the nitty gritty details of MD5 (you can read it at the IETF website here) but it provides "good enough" uniqueness for hashes generated with it. It's also one way, so there is no [easy] way to get the email back
To construct your img tag, you will need to format the request as follows:
First send the request to: http://www.gravatar.com/avatar.php? with the email hash to follow in the format: Gravatar_ID=(Email Hash). An optional Rating can be added to make sure you don't end up with XXX gravatars on your family-only site. Therefore, the optional rating=.
Additional options: Default, Size, & border. Some additional conveniences to allow you to customize it to your liking.
Now the million dollar question...The MD5 hash is a bit complex to generate, so How can I do it?
I started to write my own implementation when I stumbled over a very nice little implementation that is available in VBS and Javascript. All you need to do is include it in your ASP and you get a nice MD5 hash, you can get it here http://www.frez.co.uk/freecode.htm#md5 (I have also copied it to my server in case that site is no longer available, you can get it here: http://blog.sweetestmemories.com/media/md5.zip
So in your ASP just add [--!#include virtual="md5"--] and in your code just use the function MD5() to return the MD5 hash of the email (example: [img src="http://www.gravatar.com/avatar.php?GravatarID=[%=md5(username%]....etc) (remember to change [ and ] and swap them with < and > respectively
And that's boys and girls how you can have it on your ASP site, Enjoy
Memories....
I wish PHP was there a few years back when I was 100% Unix ;)
this semester i was introduced to Linux, I did some C/C++ on linux, using pipes and i solved some Assignments on the "NachOS"...
so can you tell me what this Linux can do for me as a technical in the future ??
or can you recommend me certain topics that I could learn of linux??
im still a beginner...
But, C/C++/C# are portable you can have good experiences in those. Focus on data structures and algorithms of course, logic design and analysis are very important and microprocessors and computer architecture are a must. And finally Software engineering principles. That's what I can think of now, I'll let you know when I remember. I'm excited, I'm going to watch the Omen :D
I've taken more that one course on each of the subjects u mentioned above, and I worked many real time projects on these subjects..I think I'll ask Jadmadi about the linux issue
Aww bil3araby: Bee (not me :P) maskhal?