It’s been more than two years since I posted a simple tutorial on Thumbs Up Thumbs Down Voting with PHP, MySQL and jQuery. That post receives the second most page-views on this blog. People created voting scripts on it. More and more talks happened on its security. Some even mailed me. And admittedly, it was least secure. Refresh the page and vote again! But then again, it was just to show how things work and not meant for production at all.
Over the past few weekends, I was working on a PHP Script that’s easy to integrate and somewhat more secure. Pulse Lite is a free and open-source thumbs-up thumbs-down ajax voting script written in PHP, using MySQL database. The requirements are minimal — PHP 5.2 or above, and MySQL. You can integrate it with your existing web-application in a matter of minutes.

Features

  • Easy to integrate!
  • Free and open-source!
  • Requirements: PHP 5.2+ and MySQL
  • Easy to customise!
  • Let’s you choose the format of the vote results!
  • Does not mess with your data! Only a single table contains the votes and other data.
  • Ready for your next project!
  • New in v2: Now, with two new styles — YouTube-styled and Reddit-styled buttons!
  • Github repository is ready to be forked!
UPDATE: A premium version of PulseLite — PulsePro — is now available! Here's a comparison of what you get!

Security

The script uses a two-fold security measurement — it logs the IP of the user and sets a cookie. So whenever a user tries to vote on an item, the script checks the IP and the cookie. If they exist in the database (IP) and on users machine (cookie), the script stops the user from voting.
This is not bulletproof, though. The user can use a different IP address and clear the cookie in order to vote again. And apparently, there is no bulletproof security measurement for such a situation. The best possible case is when a user is logged in and votes on an item. We can then lock user’s ID and stop voting next time s/he tries. A premium version is under work which will have more features. Stay in touch!

Installation

  • Download the zip file (link is at the top). Unzip and run the SQL file included in it.
  • Edit pulse.config.php file inside the main Pulse directory. Fill in your database credentials. Also, fill in PULSE_DIR with the absolute path of the Pulse directory (i.e. the path of the Pulse directory inside your server)
  • Edit /assets/js/pulse.core.js file. Edit the value of u (i.e. the line that starts with var u). Set the value of u to the same value as PULSE_DIR
  • Include Pulse.vote.class.php to the file(s) where you want to show pulse. Create an instance of Pulse.
    include("Pulse/Pulse.vote.class.php");
    $pulse = new Pulse();
    
  • Inside the head tag, add these lines to include necessary JS and CSS files.
    <?php echo Pulse::css(); ?>
    <?php echo Pulse::javascript(); ?>
    
  • Inside the loop of the items (which are to be voted), add this line.
    <?php echo $pulse->voteHTML($item_id); ?>
    Here $item_id is the id of the item which is to be voted. Add the above line wherever you want to show the vote buttons
  • You can specify the format in which the results are to be shown. Just after you create the $pulse instance, add this line.
    $pulse->setFormat("{up} like it, {down} don't");
    Here {up} will be replaced by the number of upvotes and {down} with that of downvotes. You can also use {balance} for the difference between upvotes and downvotes.

Support

While this is an open-source project, I cannot guarantee providing support for the installation you can send me a mail in case you need any installation and customization, for a quote. All necessary installation guide and database structure are included with the source. An extensive sample installation can be found here for a better understanding.

Would you find any issues, feel free to discuss in the comment section. I hope you would enjoy using it as much as I did building it.

Labels: , , ,

blog comments powered by Disqus