would like to see cookies implemented to stop people
from ranking a blog over and over. could be set with
a timer of anywhere from 24hours-a week. i know
people can delete cookies but it would be an
improvement over what is currently in place.
What I want to do is after you vote it will write your IP to a text file called ip.txt in the same folder the
script currently writes the rating.txt ('content/'.$y.'/'.$m.'/'.$entry.'/). I want it to check that ip.txt file to
see if your ip is there, if it is then it doesn’t write the new vote. I am sure this can be done rather quickly;
after messing around with sb_entry.php under the scripts folder i finally figured out a solution to stop people from voting on an entry over and over. what it does is check for an ip address in ip.txt (same folder as rating.txt), if the ip address in the file is your ip address it will not allow you to vote. if it is a different ip then you can vote. what this means is that you cant click to vote over and over UNLESS the ip in the file has changed (i.e. someone else votes on it or your ip address changes). the ip.txt contains only one ip address at a time so it is a really small file. if the file is not there, it will write after you vote. i know this doesn't completly stop multiple votes but is a much better solution than what is there. i am using it on my blog now and it works GREAT!!!! i thought i would share.
replace the function write_rating in the sb_entry.php file with this.
function write_rating( $y, $m, $entry, $rating ) {
Cookies will not solve that problem simply because the user can ignore them. What we need, and we need it urgently, is a spam-stopper, e.g. the user has to enter a code given in an image. Or registered users.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=1622608
What I want to do is after you vote it will write your IP to a text file called ip.txt in the same folder the
script currently writes the rating.txt ('content/'.$y.'/'.$m.'/'.$entry.'/). I want it to check that ip.txt file to
see if your ip is there, if it is then it doesn’t write the new vote. I am sure this can be done rather quickly;
// ----------------
// Rating Functions
// ----------------
function write_rating( $y, $m, $entry, $rating ) {
// Save Rating
$result_array = read_rating( $y, $m, $entry, $rating );
if ( $result_array ) {
$result_array[ 'points' ] = $result_array[ 'points' ] + $rating;
$result_array[ 'votes' ] = $result_array[ 'votes' ] + 1;
} else {
$result_array = array();
$result_array[ 'points' ] = $rating;
$result_array[ 'votes' ] = 1;
}
$str = '';
$keys = array_keys( $result_array );
for ( $i = 0; $i < count( $keys ); $i++ ) {
$key = $keys[ $i ];
if ( $i > 0 ) {
$str = $str . '|';
}
$str = $str . $key . '|' . $result_array[ $key ];
}
$dir = 'content/'.$y.'/'.$m.'/'.$entry;
if ( !file_exists( $dir ) ) {
$oldumask = umask( 0 );
$ok = mkdir( $dir, 0777 );
umask( $oldumask );
if ( !$ok ) {
return( NULL );
}
}
$filename = 'content/'.$y.'/'.$m.'/'.$entry.'/rating.txt';
sb_write_file( $filename, $str );
}
function read_rating( $y, $m, $entry ) {
// Read the rating.txt file and return the stored data.
//
// Returns NULL on fail.
$rating_path = 'content/'.$y.'/'.$m.'/'.$entry.'/';
$contents = sb_read_file( $rating_path . 'rating.txt' );
if ( $contents ) {
$result_array = array();
$data_array = explode('|', $contents);
$key_array = array( 'points', 'votes' );
for ( $i = 0; $i < count( $data_array ); $i = $i + 2 ) {
for ( $j = 0; $j < count( $key_array ); $j++ ) {
if ( $data_array[ $i ] == $key_array[ $j ] ) {
$key = $key_array[ $j ];
$result_array[ $key ] = intval( $data_array[ $i+1 ] );
}
}
}
return( $result_array );
}
}
_________________
Logged In: YES
user_id=1622608
Originator: YES
here is what i did:
after messing around with sb_entry.php under the scripts folder i finally figured out a solution to stop people from voting on an entry over and over. what it does is check for an ip address in ip.txt (same folder as rating.txt), if the ip address in the file is your ip address it will not allow you to vote. if it is a different ip then you can vote. what this means is that you cant click to vote over and over UNLESS the ip in the file has changed (i.e. someone else votes on it or your ip address changes). the ip.txt contains only one ip address at a time so it is a really small file. if the file is not there, it will write after you vote. i know this doesn't completly stop multiple votes but is a much better solution than what is there. i am using it on my blog now and it works GREAT!!!! i thought i would share.
replace the function write_rating in the sb_entry.php file with this.
function write_rating( $y, $m, $entry, $rating ) {
$rating_path = 'content/'.$y.'/'.$m.'/'.$entry.'/';
$contents = sb_read_file( $rating_path . 'ip.txt' );
if ($contents != $_SERVER['REMOTE_ADDR']) {
// Save Rating
$result_array = read_rating( $y, $m, $entry, $rating );
if ( $result_array ) {
$result_array[ 'points' ] = $result_array[ 'points' ] + $rating;
$result_array[ 'votes' ] = $result_array[ 'votes' ] + 1;
} else {
$result_array = array();
$result_array[ 'points' ] = $rating;
$result_array[ 'votes' ] = 1;
}
$str = '';
$keys = array_keys( $result_array );
for ( $i = 0; $i < count( $keys ); $i++ ) {
$key = $keys[ $i ];
if ( $i > 0 ) {
$str = $str . '|';
}
$str = $str . $key . '|' . $result_array[ $key ];
}
$dir = 'content/'.$y.'/'.$m.'/'.$entry;
if ( !file_exists( $dir ) ) {
$oldumask = umask( 0 );
$ok = mkdir( $dir, 0777 );
umask( $oldumask );
if ( !$ok ) {
return( NULL );
}
}
$filename = 'content/'.$y.'/'.$m.'/'.$entry.'/rating.txt';
sb_write_file( $filename, $str );
$filename = 'content/'.$y.'/'.$m.'/'.$entry.'/ip.txt';
sb_write_file( $filename, $_SERVER['REMOTE_ADDR'] );
}
}
Logged In: YES
user_id=987779
Originator: NO
Cookies will not solve that problem simply because the user can ignore them. What we need, and we need it urgently, is a spam-stopper, e.g. the user has to enter a code given in an image. Or registered users.