Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Poll without a database
Old 04-27-2004, 02:01 PM Poll without a database
David43's Avatar
Online Anarchist

Posts: 360
Trades: 0
Hi all, I hope you can all help me out with this problem. I'm trying to add a poll to my new site layout, although the problem being I have no database I can use for this. At the moment I have found a script which allows me to use a poll with no forum but I can't display it directly on my site. It has it's own url of http://www.boavid.com/poll/poll.php

I have made the template so the user has to click on the 'Vote Now' text to be carried through to the poll, although I'd like to ideally have the poll so it displays on the page and there isnt a need to click through to it.

Does anybody have any ideas about how I can do this at all?

The current script I'm using is called simplepoll-1.0. If anybody knows how I can get this to display on my site or can suggest a better alternative, please post back and let me know.
David43 is offline
Reply With Quote
View Public Profile Visit David43's homepage!
 
 
Register now for full access!
Old 04-28-2004, 10:11 AM
Average Talker

Posts: 15
Trades: 0
You can write (or find in the Internet) CGI poll script which does not require database and put poll on your page using SSI.
__________________
Software outsourcing / Free bulletin board, hit counter and banner exchange services

Please login or register to view this content. Registration is FREE
Masterhard is offline
Reply With Quote
View Public Profile
 
Old 04-28-2004, 04:54 PM
David43's Avatar
Online Anarchist

Posts: 360
Trades: 0
Could you suggest any CGI scrip in particular?
David43 is offline
Reply With Quote
View Public Profile Visit David43's homepage!
 
Old 04-29-2004, 04:43 AM
Average Talker

Posts: 15
Trades: 0
Quote:
Originally Posted by David43
Could you suggest any CGI scrip in particular?
Huh... It is so easy to write such poll script... Here we go

Here is the script.

File poll.cgi
Code:
#!/usr/bin/perl

use strict;
use CGI qw(:all);

my $poll_id = int(param('poll'));
my $action;

open FH, "poll_${poll_id}_ip.txt";
my $ip = <FH>;
close FH;
chomp $ip;
$ip = defined($ip) ? $ip : '';
if ($ip eq '') { $ip = ':' }
my $pat = join('\.', split(/\./, $ENV{'REMOTE_ADDR'}));
my $mode = $ip =~ /\:$pat\:/ ? 0 : 1;
if (($mode == 0) || defined(param('see'))) {
  print "Content-Type: text/html\n\n";
  print "<center>Poll results</center>\n";
  open FH, "poll_${poll_id}_text.txt";
  my @lines = <FH>;
  close FH;
  print join("<br>", @lines);
  open FH, "poll_${poll_id}_lines.txt";
  my @lines = <FH>;
  close FH;
  open FH, "poll_${poll_id}_results.txt";
  my @votes = <FH>;
  close FH;
  my $sum = 0;
  foreach (@votes) {
    $sum += int($_);
  }
  print "<center><table border=0 cellspacing=0 cellpadding=4>";
  for (my $i = 0; $i <= $#lines; $i++) {
    my $width = 200;
    my $a = int($votes[$i] * $width / $sum);
    my $b = $width - $a;
    print "<tr><td align=right>$lines[$i] (".int($votes[$i]).")</td><td><table width=$width height=10><tr><td width=$a bgcolor=red></td><td width=$b bgcoloe=blue></td></tr></table></td></tr>";
  }
  print "</table></center>";
} else {
  if (defined(param('dovote'))) {
    my $vote = int(param('vote'));
    open FH, "poll_${poll_id}_lines.txt";
    my @lines = <FH>;
    close FH;
    if ($vote > $#lines) {
      print "Content-Type: text/html\n\nError";
      exit 0;
    }
    open FH, "poll_${poll_id}_results.txt";
    my @lines = <FH>;
    close FH;
    foreach (@lines) {
      chomp $_;
    }
    $lines[$vote] = int($lines[$vote]) + 1;
    open FH, ">poll_${poll_id}_results.txt";
    print FH join("\n", @lines);
    close FH;
    open FH, ">poll_${poll_id}_ip.txt";
    print FH "$ip$ENV{'REMOTE_ADDR'}:";
    close FH;
    print redirect(-uri => $ENV{'HTTP_REFERER'});
  } else {
    print "Content-Type: text/html\n\n";
    print "<form action=/cgi-bin/poll.cgi method=post>";
    print "<input type=hidden name=poll value=$poll_id>";
    open FH, "poll_${poll_id}_text.txt";
    my @lines = <FH>;
    close FH;
    print join("<br>", @lines);
    print "<center><table border=0 cellspacing=0 cellpadding=4>";
    open FH, "poll_${poll_id}_lines.txt";
    my @lines = <FH>;
    close FH;
    for (my $i = 0; $i <= $#lines; $i++) {
      print "<tr><td align=center><input type=radio name=vote value=$i></td><td>$lines[$i]</td></tr>";
    }
    print "<tr><td align=center colspan=2><input type=submit name=dovote value=Vote> <input type=submit name=see value=\"See results\"></td></tr>";
    print "</table></center>";
    print "</form>";
  }
}
Requirements: http server must have write access to config files.
Configuration:

To create poll
1. Create file "poll_X_text.txt" (replace X with integer poll identifier e.g. "1") and put there poll question.
2. Create file "poll_X_lines.txt" with referred answers (1 answer per line)
3. Put on your page SSI call: <!--#include virtual="/cgi-bin/poll.cgi?poll=X"-->

Poll rules: a client can vote once. After he votes, his IP is stored and script shows him results page.

Example

poll_1_text.txt
Code:
Do you like it?
poll_1_lines.txt
Code:
Yes.
No.
May be.
Do I like what???
__________________
Software outsourcing / Free bulletin board, hit counter and banner exchange services

Please login or register to view this content. Registration is FREE
Masterhard is offline
Reply With Quote
View Public Profile
 
Old 04-29-2004, 12:25 PM
David43's Avatar
Online Anarchist

Posts: 360
Trades: 0
Thanks for the code, I'll try setting it up over the weekend and see how I get on. It seems pretty straighforward though, I never knew it was so simple.
David43 is offline
Reply With Quote
View Public Profile Visit David43's homepage!
 
Old 05-01-2004, 12:51 PM
David43's Avatar
Online Anarchist

Posts: 360
Trades: 0
I've tried to set it all up, although I must be doing something wrong for it not to work. Maybe its the paths. I've put the files in my CGI BIN under poll.
Here are the three files, could you have a check to make sure they're in order? -

poll_1_text -
Code:
Which Bo Selecta series did you prefer?
poll_1_lines -
Code:
Series 1
Series 2
poll.cgi -
Code:
#!/usr/bin/perl

use strict;
use CGI qw(:all);

my $poll_id = int(param('poll'));
my $action;

open FH, "poll_${poll_id}_ip.txt";
my $ip = <FH>;
close FH;
chomp $ip;
$ip = defined($ip) ? $ip : '';
if ($ip eq '') { $ip = ':' }
my $pat = join('\.', split(/\./, $ENV{'REMOTE_ADDR'}));
my $mode = $ip =~ /\:$pat\:/ ? 0 : 1;
if (($mode == 0) || defined(param('see'))) {
  print "Content-Type: text/html\n\n";
  print "<center>Poll results</center>\n";
  open FH, "poll_${poll_id}_text.txt";
  my @lines = <FH>;
  close FH;
  print join("<br>", @lines);
  open FH, "poll_${poll_id}_lines.txt";
  my @lines = <FH>;
  close FH;
  open FH, "poll_${poll_id}_results.txt";
  my @votes = <FH>;
  close FH;
  my $sum = 0;
  foreach (@votes) {
    $sum += int($_);
  }
  print "<center><table border=0 cellspacing=0 cellpadding=4>";
  for (my $i = 0; $i <= $#lines; $i++) {
    my $width = 200;
    my $a = int($votes[$i] * $width / $sum);
    my $b = $width - $a;
    print "<tr><td align=right>$lines[$i] (".int($votes[$i]).")</td><td><table width=$width height=10><tr><td width=$a bgcolor=black></td><td width=$b bgcoloe=blue></td></tr></table></td></tr>";
  }
  print "</table></center>";
} else {
  if (defined(param('dovote'))) {
    my $vote = int(param('vote'));
    open FH, "poll_${poll_id}_lines.txt";
    my @lines = <FH>;
    close FH;
    if ($vote > $#lines) {
      print "Content-Type: text/html\n\nError";
      exit 0;
    }
    open FH, "poll_${poll_id}_results.txt";
    my @lines = <FH>;
    close FH;
    foreach (@lines) {
      chomp $_;
    }
    $lines[$vote] = int($lines[$vote]) + 1;
    open FH, ">poll_${poll_id}_results.txt";
    print FH join("\n", @lines);
    close FH;
    open FH, ">poll_${poll_id}_ip.txt";
    print FH "$ip$ENV{'REMOTE_ADDR'}:";
    close FH;
    print redirect(-uri => $ENV{'HTTP_REFERER'});
  } else {
    print "Content-Type: text/html\n\n";
    print "<form action=/cgi-bin/poll.cgi method=post>";
    print "<input type=hidden name=poll value=$poll_id>";
    open FH, "poll_${poll_id}_text.txt";
    my @lines = <FH>;
    close FH;
    print join("<br>", @lines);
    print "<center><table border=0 cellspacing=0 cellpadding=4>";
    open FH, "poll_${poll_id}_lines.txt";
    my @lines = <FH>;
    close FH;
    for (my $i = 0; $i <= $#lines; $i++) {
      print "<tr><td align=center><input type=radio name=vote value=$i></td><td>$lines[$i]</td></tr>";
    }
    print "<tr><td align=center colspan=2><input type=submit name=dovote value=Vote> <input type=submit name=see value=\"See results\"></td></tr>";
    print "</table></center>";
    print "</form>";
  }
}
I've added them to the page www.boavid.com/index-NEW.php
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by David43; 05-01-2004 at 01:46 PM..
David43 is offline
Reply With Quote
View Public Profile Visit David43's homepage!
 
Old 05-02-2004, 07:54 AM
Average Talker

Posts: 15
Trades: 0
Quote:
Originally Posted by David43
I've tried to set it all up, although I must be doing something wrong for it not to work. Maybe its the paths. I've put the files in my CGI BIN under poll.

-- cut --

I've added them to the page www.boavid.com/index-NEW.php
Your web server (apache?) is not set up to use SSI on PHP pages.
First try to create "index-new.shtml" file. I think this will help you.
__________________
Software outsourcing / Free bulletin board, hit counter and banner exchange services

Please login or register to view this content. Registration is FREE
Masterhard is offline
Reply With Quote
View Public Profile
 
Old 05-03-2004, 04:05 PM
David43's Avatar
Online Anarchist

Posts: 360
Trades: 0
So changing the pages to shtml format should get the poll to appear.

Is there anyway around doing this, my pages use a lot of PHP and server side includes which I'm not sure will still work with shtml pages. Would I be able to perhaps create an include using the code as shtml format and put the include in the PHP page?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
David43 is offline
Reply With Quote
View Public Profile Visit David43's homepage!
 
Reply     « Reply to Poll without a database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.51135 seconds with 12 queries