473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Modifying Rating Script

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
4 1618
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SteveS | last post by:
Hello, this problem is driving me nuts! I am using the Content Ratings (RSACi) for my website. The settings strictly "G" rated - No violence, sex, nudity or offensive language. I have a user...
2
by: alex | last post by:
I need a more advanced formula than just an average for calculating items rating. I have: raitng value is on scale 1 to 10. s - sum of all ratings for an item n - number of rates (votes)
8
by: kp87 | last post by:
I am a little bit stuck .... I want to play a bunch of soundfiles randomly, but i want to give each soundfile a rating (say 0-100) and have the likelihood that the file be chosen be tied to its...
2
by: Baron Samedi | last post by:
I am looking for a simple rating script whcih does not require SQL. Thanks in advance for any help.
7
by: kArTiK | last post by:
Does ne one have a Rating script same as on google groups... the one wid stars..n the rating gets saved too...in some variable.. plz help...urgently required
15
by: Inny | last post by:
Hello, I found this simple js star rating script that I want to modify slightly. firstly I want to retain current vote , say 3 stars, untill its changed again. right now it resets to unvoted...
1
by: lamarant | last post by:
Hi...I'm trying to use the Rating Control in the Ajax Toolkit in a datalist. I have the control showing up in the list, with the logged in users current rating for each item in the list showing... ...
4
by: MissElegant | last post by:
Hi every body I wanna find someone in here who'd create me a 5-star rating system for my website using Javascript. The script should accept the rating a user made and place a cookie on the...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.