Hi to everyone. I am in need of a script for voting, as the simple he is, as hard to find over the internet.

For example on my page i have a link "click to vote" and next to it "votes by now: 320"

If a user click the link (or button, thing that i will decide later), it will be replaced with "you have voted" and "votes by now" update to "321"

And of course only 1 vote / ip to be allowed, not for only 24 hours or 1 year, but forever, if an ip voted already, he cannot vote not even 10 years later for example.

I dont need template or else things to the script since it will be on my site and i will only add the link or button for vote and next to it the votes count.

So as simple as it can be so i add it easyer and i don't need cookie or else protections, only ip protection, as i already mentioned, one forever vote per ip.

I will insert link and counter and of course i will do the db needed for script, only to tell me tables and rows to add at the script db.

Sorry for my english and if i wasn't so explicit, ask for more details you need.

Thank's for waste time for me 🙂

    The problem with limiting votes by IP address is that people's IP addresses change, sometimes rarely, sometimes multiple times per day, depending on how they are connected to the internet. But whatever criteria you choose to use, you'll need to record the votes in a database table (in your example using the IP address as one field, and defining that field to have a unique index so that duplicates are not allowed. Then to get the total votes you could just get a count() on that table in your DB query.

      NogDog, i know that many ppl changes their ip depending on pc usage or moedm, simpely to sai, dynamic ip, i know that issue, but my site doesen't need protection for multiple votes from one person using more ip's getting as many votes each one from one ip is enough, i don't care if a person changes ip and vote 1000 times, it is not a contest site, as much votes, as good to be, all i need is that votes number = ip's number, and is i told, an ip can only once vote forever.

      I may help you to help me 😛
      With some help, i did to get a code, but for some reasons (i think functions not defined and called) is not working.

      First of all, i created in my db, a table named "voting" containing 2 rows:
      1'st row: id, int(11), not null, auto_increment
      2'nd row: ip varchar(15), latin1_swedish_ci, not null

      Than votnig script file called "votnig.class.php"

      <?php
      
      session_start();
         include("config.php");
      class voting {
      
         public function isReg() {
            $sql = "SELECT ip FROM `votes` WHERE ip = '{$_SERVER['PHP_SELF']}'";
            $r = mysql_query($sql) or die($sql);
            if (mysql_num_rows($r) === 0) {
               return true;
            }
            return false;
         }
      
         public function register() {
            if (self::isReg()) {
               $sql = "INSERT INTO `votes` (`ip`) VALUES ('{$_SERVER['PHP_SELF']}')";
               mysql_query($sql) or die($sql);
               return true;
            }
            return false;
         }
      
         public function numVotes() {
            $sql = "SELECT COUNT(*) FROM `votes`";
            $r = mysql_query($sql) or die($sql);
            return mysql_result($r, 0);
         }
      }
      ?>
      

      Ok, and the code that i added to my site page:

      <?php
      
         include("voting.class.php");
      
         if (!empty($_GET['vote'])) {
            if (voting::register()) {
               ?>Participi la campanie<?php
            } else {
               ?>Te-ai inregistrat deja<?php
            }
         }
      
         if (voting::isReg()) {
            ?><a href="?vote=1">Voteaza!</a><?php
         } else {
            ?>Participi la campanie. Avem<?php echo voting::numVotes();
         }
      ?>
      

      Ok, i am not sure, but if this requires login, it should be removed, i don't use login on my site, i need anyone who enters can vote directly by clicking link or button(i will decide what to use as i already told in first post)

      Ok and the problem i got with this code, it gives no error, but instead, everything on my page (except background image vanish and it displays the message:

      SELECT ip FROM `votes` WHERE ip = '/site name/index.php'
      

      That's my site adress, better say, a sub-site bechause this voting site is only in a folder of my main site, only a campaign like sitename.com/forum and instead of index, file is called else, the file where the voting will be dispalyed.

      I hope so much that with ur help i will get script work 🙁
      Thank's alot.

        Write a Reply...