You are here: Re: Modifying Rating Script « PHP Programming Language « IT news, forums, messages
Re: Modifying Rating Script

Posted by Jerry Stuckle on 11/15/06 19:57

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.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация