Accessible ASP Star Ratings Script Version 0.2

Homepage > ASP Scripts > Accessible ASP Star Ratings Script

I'm sure you've seen the star ratings feature dotted about the web on sites such as Amazon and YouTube. I couldn't find a ready made ASP script for this so decided to make one myself.

The Star Ratings script uses an Access database and should run on just about any ASP enabled Windows server.

If you use this on your website please let me know, I'd love to see it in action elsewhere. I'll also add a link to your site on the demo page.

Features

  • Uses AJAX if Javascript is enabled but functions identically without Javascript.
  • Logs IP addresses to prevent multiple votes for the same page.
  • Block custom IP ranges and/or User Agents to prevent bots and spiders voting.
  • Works with dynamic URLs.
  • Free for personal or commercial use.
  • Quick and easy to set up.

Demonstration

Download script

Installation

Upgrading

If you're upgrading the script from an earlier version simply overwrite the existing files, making sure you don't overwrite your database with the empty one in the .zip file. You will also need to make a note of your settings in common.asp.

First time installation

Download and extract the .zip file above to a directory named "rating" in the root directory of your website.

Add the following code between the <head> tags of your page:

<script type="text/javascript" src="/rating/rating.js"></script>
<link type="text/css" rel="stylesheet" href="/rating/rating.css" />

Add this code wherever you want the rating bar to appear on your page:

<!--#include virtual="/rating/rating.asp"-->

No further setup is required for this script to run "out of the box". However I can't stress strongly enough that you must upload to the "/rating/" directory to the root directory of your website. If you upload the files to anywhere else then the script won't work without further changes (see below).

Database

This script uses a Microsoft Access 2000 database, included in the .zip file. By default the database is located in the "/rating/" directory with all of the other files and as such could be downloaded by anyone. Since the database probably won't contain any sensitive data this shouldn't be a problem.

However, if you would like to store the database outside the web root then alternative connection strings are provided in common.asp.

Uploading the script to a directory other than "/rating/"

If you want to store the files in a directory other than "/rating/", for example "/scripts/rating/", you will need to edit the RATING_DIR constant in common.asp as follows:

RATING_DIR = "scripts/rating"  '- DO NOT start or end with /

You will also need to edit the image paths in rating.css as follows:

#star-rating ul {
  background: url(/scripts/rating/rating.gif) top left repeat-x;
}
#star-rating li.current-rating {
  background: url(/scripts/rating/rating.gif) left bottom;
}
#star-rating li a:hover {
  background: url(/scripts/rating/rating.gif) left center;
}

Change the path to the CSS and Javascript files between the <head> tags of your page:

<script type="text/javascript" src="/scripts/rating/rating.js"></script>
<link type="text/css" rel="stylesheet" href="/scripts/rating/rating.css" />

And finally change the include path to the rating script:

<!--#include virtual="/scripts/rating/rating.asp"-->

Blocking IP Ranges

Open common.asp and scroll down to the "Blocked IP Ranges" section. To block an entire IP range use the AddBlockedIPRange subroutine as shown below and replace the lower and upper IP addresses as required:

AddBlockedIPRange "192.168.0.1", "192.168.0.10"

An excellent list of search engine IP addresses and User Agents can be found at www.IPLists.com.

Blocking User Agents

Open common.asp and scroll down to the "Blocked User Agents" section. To block a User Agent, use the AddBlockedUserAgent subroutine as shown below:

AddBlockedUserAgent "Googlebot"
AddBlockedUserAgent "MSNBOT/0.1"

A list of robot and search engine User Agents can be found here at JafSoft.com.

Blocking User Agent Strings

As well as blocking specific User Agents, you can also block User Agents that contain certain strings, such as "crawler" or "spider".
Open common.asp and scroll down to the "Blocked User Agent Strings" section. To block User Agents containing a certain string, user the AddBlockedUAString as follows:

AddBlockedUAString "crawler"
AddBlockedUAString "spider"

Credits

The XHTML/CSS has been taken from Creating a Star Rater using CSS written by Rogie King at Komodo Media.

The AJAX framework the script uses is the Simple/Basic AJAX Framework by Ric Hardacre at Cyclomedia. It has been tested to work with Internet Explorer 5.0, 5.5, 6.0 and 7.0, Opera 8.0 and 8.5, Netscape 7.0 and Firefox 1.5

Please rate this script!

Rated: ASPIN.com rating by Aspin.com users

What do you think?

Comments have been disabled.