473,614 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1626
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*******@attgl obal.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*******@attgl obal.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_arra y = read_rating( $y, $m, $entry, $rating );
if ( $result_array ) {
$result_arra y[ 'points' ] = $result_array[ 'points' ] + $rating;
$result_arra y[ 'votes' ] = $result_array[ 'votes' ] + 1;
} else {
$result_arra y = array();
$result_arra y[ 'points' ] = $rating;
$result_arra y[ '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_fil e( $filename, $str );

}

function read_rating( $y, $m, $entry ) {
// Read the rating.txt file and return the stored data.
//
// Returns NULL on fail.
$rating_pa th = 'content/'.$y.'/'.$m.'/'.$entry.'/';
$contents = sb_read_file( $rating_path . 'rating.txt' );

if ( $contents ) {
$result_arra y = array();

$data_arra y = 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_arra y[ $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*******@attgl obal.net
=============== ===
Nov 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1403
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 who also has his "Content Advisor" turned on. For some reason, the session is lost for the user ONLY after he runs a javascript function on the page, then clicks submit. Make sense? If he clicks submit without first running any javascript ,...
2
2917
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
1989
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 rating so that the higher the rating the more likely a file is to be chosen. Then i need some additional flags for repetition, and some other business. I am guessing a dictionary would be a great way to do this, with the key being the soundfile...
2
2310
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
1308
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
3942
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 on refresh. I know you could use cookies but I also want to give it a unique identifier so that if i put it in my topic header templet, its unique to each topic (retaining whatever vote for each topic untill changed again) . perhaps this is not...
1
2837
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... <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatLayout="Flow"> <ItemTemplate> <div class="Rating"> <ajaxToolkit:rating ID="SongRating" runat="server" ...
4
3519
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 computer to remember what rating the user made. More than 10 of them should work on one page as well! Please help me. PS: Only use javascript and html of course.
5
2629
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. In a nutshell, I understand how this can be considered desireable by some, but I am not one of those people. My situation is that we have a root site (hosted @ http://www.mydomain.com) in the root application folder '/'.
0
8142
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6093
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.