rate.php 715 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require_once("apps.inc");
  3. //
  4. // try to prevent external rating scripts
  5. //
  6. if( isset($APP_RATE_COOKIE) ) {
  7. $ratingAry = unserialize(base64_decode($APP_RATE_COOKIE));
  8. }
  9. if( !is_array($ratingAry) ) {
  10. $ratingAry = array();
  11. }
  12. if( $rate >= 1 && $rate <= 5 && !array_key_exists($app_id, $ratingAry) && ereg("http://$_SERVER[SERVER_NAME]/apps", $_SERVER[HTTP_REFERER]) ) {
  13. mysql_query("
  14. UPDATE app
  15. SET
  16. rating = (rating * votes + $rate) / (votes + 1),
  17. votes = votes + 1
  18. WHERE id = $app_id
  19. ");
  20. $ratingAry[$app_id] = 1;
  21. SetCookie("APP_RATE_COOKIE", base64_encode(serialize($ratingAry)), time()+86400, '/' );
  22. }
  23. include_once("index.php");
  24. ?>