By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,277 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,277 IT Pros & Developers. It's quick & easy.

Modifying Rating Script

P: n/a
If you have a few minutes, I would like to see if anyone can help me
out. I'm trying to modify a rating script. Currently, It allows you
to vote over and over. 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; I'm just stuck
since I do not know a lot of php (still learning).
Here is the current function. (also in text file:
http://www.margaritatexas.com/rating.txt)


// ----------------
// 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 );
}
}
_________________

Nov 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
bp90210 wrote:
If you have a few minutes, I would like to see if anyone can help me
out. I'm trying to modify a rating script. Currently, It allows you
to vote over and over. 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; I'm just stuck
since I do not know a lot of php (still learning).
Here is the current function. (also in text file:
http://www.margaritatexas.com/rating.txt)


// ----------------
// 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 );
}
}
_________________
Don't even try to test by ip address.

First of all, those with proxy servers (i.e. a lot of corporations) will
have all users with the same ip address. And those with multiple
proxies, like AOL, can provide a different IP address for each request
to the server.

Not to mention those with dynamic addresses which can change at any time.

If you don't want them to vote multiple times, create a sign up form
with email verification. And only allow registered users a single vote.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '06 #2

P: n/a

I heard of the term MAC address. Can it be used. No idea on how to get
it and implement.

But I guess if multiple persons are browsing from the same computer (at
home, cyber cafe), then this will not solve the problem. In that case
email will be better option.

Which will be better option :

1. If already voted, then don''t write new rating.
2. Overwrite the existing rating. e.g. I rate it as 4 (may be by
mistake), but now I feel it should be 5.
Jerry Stuckle wrote:
bp90210 wrote:
If you have a few minutes, I would like to see if anyone can help me
out. I'm trying to modify a rating script. Currently, It allows you
to vote over and over. 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; I'm just stuck
since I do not know a lot of php (still learning).
Here is the current function. (also in text file:
http://www.margaritatexas.com/rating.txt)


// ----------------
// 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 );
}
}
_________________

Don't even try to test by ip address.

First of all, those with proxy servers (i.e. a lot of corporations) will
have all users with the same ip address. And those with multiple
proxies, like AOL, can provide a different IP address for each request
to the server.

Not to mention those with dynamic addresses which can change at any time.

If you don't want them to vote multiple times, create a sign up form
with email verification. And only allow registered users a single vote.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '06 #3

P: n/a
Manish wrote:
I heard of the term MAC address. Can it be used. No idea on how to get
it and implement.

But I guess if multiple persons are browsing from the same computer (at
home, cyber cafe), then this will not solve the problem. In that case
email will be better option.

Which will be better option :

1. If already voted, then don''t write new rating.
2. Overwrite the existing rating. e.g. I rate it as 4 (may be by
mistake), but now I feel it should be 5.

-snip-

Getting a user's MAC address would allow you to find out all kinds of
different information about their computer. This means that it would
be very insecure, and lead to a whole range of privacy issues. So
don't bother.

Read about sessions - they are generally the most common form of
ratings. Still, you have to be careful about people clearing their
cookies.

TheTeapot

Nov 15 '06 #4

P: n/a
Manish wrote:
Jerry Stuckle wrote:
>>bp90210 wrote:
>>>If you have a few minutes, I would like to see if anyone can help me
out. I'm trying to modify a rating script. Currently, It allows you
to vote over and over. 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; I'm just stuck
since I do not know a lot of php (still learning).
Here is the current function. (also in text file:
http://www.margaritatexas.com/rating.txt)


// ----------------
// 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 );
}
}
_________________

Don't even try to test by ip address.

First of all, those with proxy servers (i.e. a lot of corporations) will
have all users with the same ip address. And those with multiple
proxies, like AOL, can provide a different IP address for each request
to the server.

Not to mention those with dynamic addresses which can change at any time.

If you don't want them to vote multiple times, create a sign up form
with email verification. And only allow registered users a single vote.


I heard of the term MAC address. Can it be used. No idea on how to get
it and implement.

But I guess if multiple persons are browsing from the same computer (at
home, cyber cafe), then this will not solve the problem. In that case
email will be better option.

Which will be better option :

1. If already voted, then don't write new rating.
2. Overwrite the existing rating. e.g. I rate it as 4 (may be by
mistake), but now I feel it should be 5.

(Top posting fixed)

Theoretically, the MAC address could be available to you. But that
would be the MAC address of the proxy anyway, should they be using one.
So it's not going to help you much.

About the only way to limit this is to require they sign in with an
email address you can verify before letting them vote.

But even that isn't foolproof - for instance, I have at least a dozen
different email addresses, including aliases. And I can create more at
any time. But it helps.

P.S. - Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.