0

At this time I use for voting system in my site this code (is in a PHP file but I integrated as JavaScript in hope that crawler not see that):

$rater.= '<script data-cfasync="true" type="text/javascript">';
for ($ncount = 1; $ncount <= $units; $ncount++) {
    if(!$voted) {
         $rater.='document.write("<p onClick=\"parent.location=\'\/db.php?j='.$ncount.'&q='.$id.'&t='.$ip.'&c='.$units.'\'\" style=\"cursor:pointer\" class=\"r'.$ncount.'-unit rater\"></p>");';
    }
}
$rater.='</script>';

It's perfectly functional, but I must to make a way to take out db.php from link because google see this file and in this file is a 302 redirection .

But I found a site that is using the same rating system but find a way to make the rating system to work through the "rel" attribute.

Have anyone a clue how did they do it?

That's the original file with all php content:

<?php
/*
Page:           _drawrating.php
Created:        Aug 2006
Last Mod:       Mar 18 2007
The function that draws the rating bar.
--------------------------------------------------------- 
ryan masuga, masugadesign.com
ryan@masugadesign.com 
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
--------------------------------------------------------- */
function rating_bar($id,$units='',$static='') { 
global $LANG;
require('_config-rating.php'); // get the db connection info

//set some variables
$ip = $_SERVER['REMOTE_ADDR'];
if (!$units) {$units = 10;}
if (!$static) {$static = FALSE;}

// get votes, values, ips for the current rating bar
$query=mysql_query("SELECT total_votes, total_value, used_ips FROM `$rating_dbname`.$rating_tableName WHERE id='$id' ")or die(" Error: ".mysql_error());


// insert the id in the DB if it doesn't exist already
// see: http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/#comment-121
if (mysql_num_rows($query) == 0) {
$sql = "INSERT INTO `$rating_dbname`.$rating_tableName (`id`,`total_votes`, `total_value`, `used_ips`) VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}

$numbers=mysql_fetch_assoc($query);


if ($numbers['total_votes'] < 1) {
    $count = 0;
} else {
    $count=$numbers['total_votes']; //how many votes total
}
$current_rating=$numbers['total_value']; //total number of rating added together and stored
$tense=($count==1) ? $LANG->l('vote') : $LANG->l('votes'); //plural form votes/vote

// determine whether the user has voted, so we know how to draw the ul/li
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM `$rating_dbname`.$rating_tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' ")); 

// now draw the rating bar
$rating_width = @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);


if ($static == 'static') {

        $static_rater = array();
        $static_rater[] .= "\n".'<div class="ratingblock static">';
        $static_rater[] .= '<div id="unit_long'.$id.'">';
        $static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
        $static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">'.$rating2.'/'.$units.'</li>';
        $static_rater[] .= '</ul>';
//      $static_rater[] .= '<p class="static">('.$count.' '.$tense.') <em>This is \'static\'.</em></p>';
        $static_rater[] .= '</div>';
        $static_rater[] .= '</div>'."\n\n";

        return join("\n", $static_rater);


} else {

      $rater ='';
      $rater.='<div class="rating-text">'.$LANG->l('Rate this wallpaper:').' </div><div class="ratingblock nonstatic">';

      $rater.='<div id="unit_long'.$id.'">';
      $rater.='<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
      $rater.='<li class="current-rating" style="width:'.$rating_width.'px;">'.$rating2.'/'.$units.'</li>';

      for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
           if(!$voted) { // if the user hasn't yet voted, draw the voting stars
              $rater.='<li><a href="'.WEB_PATH.'db.php?j='.$ncount.'&amp;q='.$id.'&amp;t='.$ip.'&amp;c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
           }
      }
      $ncount=0; // resets the count

      $rater.='</ul>';
      $rater.='<p';
      if($voted){ $rater.=' class="voted"'; }
      $rater.='>('.$count.' '.$tense.')';
      $rater.='</p>';
      $rater.='</div>';
      $rater.='</div>';
      return $rater;
 }
}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • What is inside the db.php? If you type in the url of the db.php whats the output? Thats the only thing a crawler gets. Btw: Why do you name a voting file db.inc? Is there any database specific included? If so, don't do that, make a own db.php an include that file inside your vote.php – 23tux Oct 26 '12 at 09:01
  • The db.php recording the vote in to mysql. Are lots of php functions to verify if the IP voted other times on the same item... I don't know almost nothing about PHP, but i guess the all i need is a function to call "db.php" when the user click on rating star. – user1776485 Oct 26 '12 at 09:05
  • Would be easier if you answer all my questions – 23tux Oct 26 '12 at 09:06
  • If you type in the url of the db.php whats the output? (in the db.php is a last line "header" that redirect you in the exact page you come from) And if you type "domain.com/db.php" the bwrowser return "The page isn't redirecting properly" but in header is set 302 redirection. – user1776485 Oct 26 '12 at 09:17
  • here is the entire script: http://trac.assembla.com/sa2008/browser/ajaxstarrater and the code that i wrote above can be found in _drawrating.php. i modified as javascript to try to make bots to not vote but it seems to be useless – user1776485 Oct 26 '12 at 11:38
  • none of your php code will be ever visible to a crawler, except you declare your code as string ;) – 23tux Oct 26 '12 at 11:55
  • my problem is not php, is what php generate, and what php generate is something like this: domain.com/db.php?j='1&... and the link is visible to bots 'cause it's part of the html! – user1776485 Oct 26 '12 at 11:59
  • why is it bad that the crawler sees this link? If you wan't to avoid this, why don't you just post to this url, instead of a get request? – 23tux Oct 26 '12 at 12:46

1 Answers1

0

If you add the attribute rel="nofollow" to the link, you tell Google (and other crawlers) not to follow the link. There's not guarantee that they will obey this, but most of them do.

An alternative is to use robots.txt (or you can use both), which can contain a list of urls or url masks that shouldn't be indexed.

You could also try to recognize crawlers in your script, but that would mean you'd have to create a list that is kept up to data and do a lot of checks on each request. Not the best option.

Anyway, I would work around this, by making db.php do nothing special if there is no logged in user. You wouldn't want a bunch of votes to be saved each time a disobeying crawler drops by, because every link is just saved anonymously. Such a voting system could easily be messed with, because one could just simulate thousands of upvotes just by scripting requests to that url.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Thank you. @GolezTrol i think the solution is to implement the same system that is on this site: http://www.hdcarwallpapers.com/amazing_porsche_car-wallpapers.html Robots.txt and "nofollow" doesn't work for many spam bots that is voting continuously. current that i've managed to put in script almost all bots don't vote but googlebot see the link and i have a bunch off error in webmastertools with "nofollow cause is 302" – user1776485 Oct 26 '12 at 12:51