Cool Poll Script for PHP

Created: October 29, 2014
Last Modified: March 8, 2021
Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Inernet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Inernet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • あなたの声でInernetを制御する
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
Subscribe to Internet Tips and Tools Feed

This script adds a custom poll to your website using PHP and MySQL:

Features:

  • Uses advanced techniques to avoid votebots
  • Choose to allow users to vote 'Other' and type in answer
  • Activate or Archive 'Other' votes
  • Close poll but still display votes
  • Works with a login script or tracks users votes by cookies and/or ip address
  • Hosted on your own server for better security
  • May use one MySQL database for all your polls
  • Fully customize look and color of polls using CSS
  • New! Automatically uses MySQLi or MySQL

Example Poll: Which Superhero is your Favorite?

Your Vote:

1. Batman
(117 votes) 26%
2. Superman
(65 votes) 15%
3. Spider-Man
(45 votes) 10%
4. Flash
(32 votes) 7%
5. Deadpool
(27 votes) 6%
6. Captain America
(20 votes) 4%
7. Hulk
(20 votes) 4%
8. Iron Man
(18 votes) 4%
9. Wolverine
(15 votes) 3%
10. Green Lantern
(11 votes) 2%
11. Other
(26 votes) 6%

Total Votes: 447

dlc_b

Download

Downloaded 0 times.
Please make a donation to reveal the download link.

Instructions

There are two files in coolpoll.zip called coolpoll.php and db.php. Unzip both files and after editing coolpoll.php upload them to your server.

Paste the following code at the very top of your web page:

<?PHP session_start(); ?>

Paste the following where you want the poll to display on your page:

<?PHP 
	$poll_secret = "secret123"; // this should match the variable $poll_password in coolpoll.php
	require_once("coolpoll.php");
?> 

Edit the following variables in coolpoll.php:

/* Edit the variables below */
$db_username="your_mysql_username"; 
$db_pw="your_mysql_password";
$server="localhost";
$database="your_mysql_database";


$poll_name = "Superhero"; // Every poll should have a unique poll name (50 characters max)

$poll_answers = array ("Batman", "Captain America", "Catwoman", "Daredevil", "Flash", 
"Green Lantern", "Hulk", "Iron Man", "Robin", "Rogue", "Shadowcat", "Spider-Man", 
"Superman", "The Tick", "Thor", "Wolverine", "Wonder Woman");

/* 	$_SESSION['user_id'] is how this script allows users to submit votes if $require_login = 1;
They must be logged
in and a $_SESSION['user_id'] must be set.  Instead, you may be using $_SESSION['username'] 
on your server.  In that case you will need to change the poll_users table
to have something like "user_id VARCHAR(50)," in place of "user_id INT unsigned," and you
will need to replace all references of $_SESSION['user_id'] in this script to $_SESSION['username']
*/
$poll_password = "secret123";
$require_login = 0; // 1 = yes; 0 = no 	
$use_cookies = 1; // 1 = Use cookies to keep track of votes. Only applies if $require_login = 0
$use_ip = 1; // Use IP Addresses to keep track of votes. Only applies if $require_login = 0
$your_login_page = "login.php"; /* Put the link to your login page here */					
$results_limit = null; // If you want to limit the results to display only the top results enter the limit here
$allow_voting = 1; // 0 = Close poll voting; 1 = Allow voting
$allow_other = 1; // 0 = Don't have "Other" field; 1 = "Other" field for user to type in answer
$admin_email = "Your name <you@email.com>"; // You will receive email if a user selects "Other" if $allow_other 
$admin_username = "Admin";
$admin_password = "random123";
/* $bar_style is the style of the percentage bar for each poll result. You can also
keep this variable blank and style the bar in a CSS style sheet because each bar
has a class='bar_style'. Also you can style each bar differently because each bar 
will have an id of bar1, bar2 etc... Example:
.bar_style { height: 1em; background-color: #bbbbbb; }
#bar1 { background-color: red; }
#bar2 { background-color: blue; }
*/
$bar_style = "background-color:#bbbbbb; height: 0.5em;";
/* It is not recommended but $allow_other = 2 will automatically show what users type into
the "Other" field as part of the poll, but they could enter off the topic answers or bad words.
$allow_other = 1 will let users type into "Other" field, but the admin will have to manually
activate the field.  An email will be sent to $admin_email when a user selects "Other". You can
email more than one address with a , separating the email addresses.

To display the "login as admin" prompt put this on the url:
www.yourwebsite.com/yourpage.html?admin=1
*/

History

March 8, 2021 - Version 1.2d - Bug Fix - Put inet_pton() inside of escape_string because on the outside mysql sometimes has an error because inet_pton() sometimes puts an unescaped single quote in the string.

March 26, 2019 - Version 1.2c - Fixed "warning: undefined variable" if PHP is set to display warnings.

August 9, 2017 - Version 1.2b - Bug fix in db.php - Changed if ($server_has_mysqli) to if ($GLOBALS["server_has_mysqli"]) throughout. Also changed $db_link->affected_rows() to $db_link->affected_rows.

5/4/2017 - Version 1.2a - 'Other' votes were not being calculated correctly on line 759. Fixed by adding && $row['votes'] >= 1

5/2/2017 - Version 1.2 - Added db.php which is required by coolpoll.php to support MySQLi and MySQL. The script automatically uses MySQLi if your server supports it.

4/26/2016 - Version 1.1d - If $results_limit is set to just display the top results now 'Other' is displayed at the bottom with all the other results tallied together.

4/26/2016 - Version 1.1c - Added option on line 49:
$hide_results = 1; // 0 = Don't hide results; 1 = Hide results until user votes

5/5/2015 - Version 1.1b - Bug Fix: If $allow_other was set to 0 then when a person voted it was not displaying the results because of two bugs: 1. Around line 770 forgot to close html select if not allowing other vote. 2. Around line 887 needed to check to make sure 'other_div' existed before trying to not display it.

1/8/2014 - Version 1.1 - Bug Fix: Even when logged in as admin was still only showing $results_limit of answers. Added || isset($_SESSION['admin_username']) to line 689 to fix and show all answers for admin.

1/8/2014 - Version 1.1 - Bug Fix: The row for each answer was being increased even if a poll answer was not being shown because it was archived. Fixed by removing answer_num++ from line 745 and adding it to lines 717 and 724.

10/29/2014 - Version 1.0 - Cool Poll Script Created

Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Inernet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Inernet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • あなたの声でInernetを制御する
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
Back to www.seabreezecomputers.com
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 0 comments.

Displaying first 50 comments.