>/D_
Published on

PHP Voting System to Increase your Inbound Links

Authors
  • avatar
    Name
    Frank
    Twitter

Having some sort of web 2 point ohish interactive component on your website is a great way to generate buzz, get users coming back to the site and even generate inbound links. One such component I have seen work well is a voting system, made so much more popular by community driven sites such as digg, reddit etc.

A voting system is fairly easy to implement on your site, take one database of items to vote on, add a script that will cast a vote at the click of a link, a pinch of javascript if need be and viola. The clever part is marketing the voting system which can have spinoffs such as increased inbound links, buzz surrounding your site and a situation where the owners or contributors (we'll call them advertisers) of the items you are voting on will market the system for you in their attempt to get more votes.

If you tie these votes into some sort of state/province/national awards for a particular vertical then you're in good stead. At this point you will want to supply an image or system that advertisers can add to their sites to promote your 'awards' and prompt their visitors to vote for them in your awards. This will require an inbound link to your site - of course.

Instead of just a promotional 'Vote for me in the X awards' type banner, why not display the current number of votes the advertiser has, or what place they are running at? A lot like the digg 'buttons' you see on blog articles with titles like 'Top X ways to Y'.

Achieving something like this is actually fairly straight forward. It hinges on the ability to reference php scripts from within img tags. When you can call a php script inside an image tag, you can then use that php script to get some information out of your database and generate an image displaying said information. This sounds a lot more difficult than it is as you are about to find out.
**
Creating the Image**

Firstly, making your php script appear as if it is an image is reasonably straight forward. You send a header back to the browser indicating what sort of image it is like so: (GIF in this case)

header ("Content-type: image/gif");

Then you output the code for the image which can be achieved with the GD library and functions such as imagegif(). As far as the img tag on the other end is concerned, despite the .php file extension, it is retrieving a file of type gif.

Now we need to create a custom image depending on the values you pull out of your database.

Using a handful of GD library functions this is also fairly easy. The process to achieve this requires firstly, passing some sort of id to the php script so that it knows what details to retrieve from the database. Having the script connect to the database and pull out the number etc. that you want. Using GD library functions to overlay this number on some other background gif. Returning the whole interwoven mess back to the browser in the guise of an everyday, run of the mill gif.

You can see in the files attached how the script very basically achieves this.

Uncomment the database details to meet your own criteria - currently the string used as an overlay on the gif is set to '900000'. A sprinkling of GD lib functions write this string to the gif using 'voting.gif' as the background. There is some hacking in there to center the string as well as resize the font size dependent on the number of characters in the string (I considered '999,999' votes as far surpassing my upper limit).

You will see at the bottom of the script a sample usage. Do not forget to get your advertisers to wrap the whole thing in a tags so that a) their users will go to the voting script on your site and actually cast a vote for your advertiser and b) your voting page will benefit from the inbound links. Also do not forget alt tags on the image so that search engines and visually impaired know what your link is all about.

Enjoy, as always let me know how you get on implementing the script and if there are any errors.