Modifying Rating Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bp90210

    #1

    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 );
    }
    }
    _______________ __

  • Jerry Stuckle

    #2
    Re: Modifying Rating Script

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

    Comment

    • Manish

      #3
      Re: Modifying Rating Script


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

      Comment

      • TheTeapot

        #4
        Re: Modifying Rating Script

        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

        Comment

        • Jerry Stuckle

          #5
          Re: Modifying Rating Script

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

          Comment

          Working...