I am at a stage where I will start to emplimement end result code. (almost)
But I have a problem. For some reason, unbeknownst to me (is that a word?)
It doesn't work!!!
Here is the code:
Expand|Select|Wrap|Line Numbers
- #!/usr/local/bin/perl -w
- use CGI qw(:standard);
- use Tie::File;
- sub irQ{
- print <<EOM;
- <h1>Thanks for voting!</h1>
- Here are your results:<a href="../results.txt">Click Here</a>
- EOM
- }
- sub inK{
- print <<EOM;
- <h2>You must wait 24 hours between each vote. </h2>
- Please try again later.
- Check out the articles <a href="http://www.liveaudiomag.com">Here</a>
- EOM
- }
- $tf = "true";
- $canI = "false";
- $ip = param(ip);
- $choice = param(choice);
- $time = time;
- tie @res, 'Tie::File', "../results.txt" or die;
- foreach $i (@res) { # Loop through the file, looking for matching ip address.
- if ($i =~ m/$ip/) { # If ip matches
- $get = substr($i, 0, 10); # Get the last time associated with this ip.
- if ($get+86400 < $time) { # If time is less than 24hrs ago
- $canI = "false"; # no push to array
- $tf = "false"; # take to can't vote page.
- } else { # If time is greater than 24hrs.
- $i =~ s/$get/$time/; # update time, for next time they vote.
- $canI = "false"; # No push to array (already have their vote)
- $tf = "true"; # take to thanks for voting page.
- }
- } else { # If no ip match
- $canI = "true"; # do push to array
- $tf = "true"; # take to thanks for voting page.
- }
- }
- if ("$canI" eq "true"){ # to push or not to push...
- push(@res, ("$time:$ip", "$choice"));
- }
- untie @res;
- print qq{Content-type: text/html\n\n};
- print qq{<html><head><title>Thanks for voting! | LiveAudioMag.com</title></head>\n};
- print qq{<body bgcolor='#000000' text='1cd90b'>\n};
- if ("$tf" eq "true") { # Which page to go to?
- irQ(); # Thanks for voting
- } else {
- inK(); # Can't vote page.
- }
- print end_html();
Notice the comments. It seems very straight forward.
Everything is spelled out very plain.
But it DOESN"T work. ???
Here is the URL.
Liveaudiomag survey.html
Anyone see where I am going wrong?