tabatha Posted February 5, 2007 Share Posted February 5, 2007 I have recently installed the i-rater platinum script and I think it is going to work fine for my purposes BUT I would like to make it so that ONLY registered members can vote. Will someone please have a look and see if this is possible within this code? Thanks! Tabatha <?php include("./admin/config.php"); include("$include_path/common.php"); global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS; global $_SESSION; if ($HTTP_POST_VARS!="") $_POST=$HTTP_POST_VARS; if ($HTTP_GET_VARS!="") $_GET=$HTTP_GET_VARS; if ($HTTP_SESSION_VARS!="") $_SESSION=$HTTP_SESSION_VARS; $img_num = $_POST['img_num']; if(!$img_num) $img_num=1; mt_srand(make_seed()); $user_id = 0; if(isset($_POST['submit_rating']) && isset($_POST['user_id']) && ($_POST['submit_rating'] >= 0 && $_POST['submit_rating'] <= 10)){ $user_id = (int) $_POST['user_id']; if(isset($_SESSION['ra'])){ $_SESSION['ra'] .= $user_id . ","; } else { $_SESSION['ra'] = $user_id . ","; } $rating = (int) $_POST['submit_rating']; $rater_id = isset($_POST['rater_id']) ? $_POST['rater_id'] : 0; if($rater_id) { $rater_sql = " and rater_id ='$rater_id' "; } else { $rater_sql = ""; } $check_ip_sql = " select * from $tb_ratings where user_id = '$user_id' $rater_sql and image_number ='$img_num' order by timestamp desc limit 0, 1 "; //echo " sql <BR> $check_ip_sql "; $check_ip_query = mysql_query($check_ip_sql) or die(mysql_error()); if(mysql_num_rows($check_ip_query)) { $last_rater_ip = @mysql_result($check_ip_query, "0", "rater_ip"); $last_rater_id = @mysql_result($check_ip_query, "0", "rater_id"); $last_rated = @mysql_result($check_ip_query, "0", "timestamp"); } else { $last_rater_ip =""; $last_rater_id =""; $last_rated =""; } $yesterday = date("YmdHis", mktime(date("H"), date("i"), date("s"), date("m"), date("d")-1, date("Y"))); $same_ip = false; $too_soon = false; $same_user = false; if($last_rater_ip == $HTTP_SERVER_VARS['REMOTE_ADDR']) $same_ip = true; if($last_rated > $yesterday) $too_soon = true; if($user_id == $rater_id) $same_user = true; //echo" <br> U $user_id R $rater_id "; //echo "<BR> same user $same_user IP $same_ip SOON $too_soon "; session_register("previous_rated_image"); $_SESSION['previous_rated_image'] ="$user_id&&$img_num"; if(!$same_user && (!$same_ip || !$too_soon)){ //echo " TEST <BR> $check_ip_sql "; exit; $rating_accepted = true; $is_sql = " insert into $tb_ratings ( id, user_id, rating, rater_id, rater_ip, image_number ) values ( '', '$user_id', '$rating', '$rater_id', '$_SERVER[REMOTE_ADDR]', '$img_num' ) "; $is_query = mysql_query($is_sql) or die(mysql_error()); $gs_sql = " select total_ratings, total_points, average_rating from $tb_users where id = '$user_id' "; $gs_query = mysql_query($gs_sql) or die(mysql_error()); $total_ratings = mysql_result($gs_query, 0, "total_ratings"); $total_points = mysql_result($gs_query, 0, "total_points"); $total_ratings++; $total_points += $rating; $average_rating = $total_points / $total_ratings; $ps_sql = " update $tb_users set total_ratings = '$total_ratings', total_points = '$total_points', average_rating = '$average_rating' where id = '$user_id' "; $ps_query = mysql_query($ps_sql) or die(mysql_error()); } } clean_ratings(); if(isset($_POST['page']) && $_POST['page'] == "index"){ if($rater_id == $user_id ) { header("Location: $base_url/?z=1"); exit; } $files_sql = " select total_files from $tb_users where id = '$user_id' "; $files_query = mysql_query($files_sql) or die(mysql_error()); $total_files = mysql_result($files_query, 0, "total_files"); if( ($img_num > 1) && ($rater_id) ) { $yesterdaytime = date("YmdHis", mktime(date("H"), date("i"), date("s"), date("m"), date("d")-1 , date("Y"))); $check_extra_sql = " select * from $tb_ratings where user_id = '$user_id' and rater_id ='$rater_id' and timestamp > '$yesterdaytime' and image_number != '1' "; $rated_result = mysql_query($check_extra_sql); $total_rated_images=mysql_num_rows($rated_result); //echo " SQL $check_extra_sql $total_rated_images ";exit; if ($total_rated_images != ($total_files-1) ) { if($img_num == $total_files ) { $next_image=2; } else { $next_image=$img_num + 1; } } else { $next_image=0; } if($next_image) { header("Location: $base_url/show_image.php?id=$user_id&p=$next_image"); exit; } else{ header("Location: $base_url/?z=1"); exit; } } else { header("Location: $base_url/?z=1"); exit; } exit(); } else { header("Location: $base_url/?v=$user_id"); exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/37097-i-only-want-regestered-members-to-be-able-to-vote-with-i-rater-script/ Share on other sites More sharing options...
smc Posted February 5, 2007 Share Posted February 5, 2007 It's impossible for us to help you out without knowing how your users login and what variables you use to assign their session. If your looking for someone to do it for you then you might want to try the Freelance section and pay someone to do it, here we help people that are giving it an honest try. Link to comment https://forums.phpfreaks.com/topic/37097-i-only-want-regestered-members-to-be-able-to-vote-with-i-rater-script/#findComment-177171 Share on other sites More sharing options...
tabatha Posted February 5, 2007 Author Share Posted February 5, 2007 OK sorry. My problem is that in this hot or nor type script, anybody can vote weather logged in or not. I thought that I might get some suggestions here. I do know a little PHP but need to get pointed in the right direction. Thought i was in the right place. Thanks for having a look:) Tabatha Link to comment https://forums.phpfreaks.com/topic/37097-i-only-want-regestered-members-to-be-able-to-vote-with-i-rater-script/#findComment-177172 Share on other sites More sharing options...
smc Posted February 5, 2007 Share Posted February 5, 2007 Well basically here is the direction. In your login.php you should set a session variable such as session_start(); $_SESSION['username']; = $my_username_after_logging_in; Then on your voting page do something like this: session_start(); if ( isset( $_SESSION['username'] ) ) { Proceed with what you need to get done; } if ( !isset( $_SESSION['username'] ) ){ Show and error telling them to login to vote; } That will see if the session variable for username is set. When logging in you set it with their username. If it is set everything will go as normal, if it's not it will show an error message. Note: isset is a PHP function to see if a particular variable is set. If there is an ! infront of the function that basically means if the function is not set. Link to comment https://forums.phpfreaks.com/topic/37097-i-only-want-regestered-members-to-be-able-to-vote-with-i-rater-script/#findComment-177175 Share on other sites More sharing options...
tabatha Posted February 5, 2007 Author Share Posted February 5, 2007 Thank you! I will give this some serious efforts and report back with the solution. Tabatha Link to comment https://forums.phpfreaks.com/topic/37097-i-only-want-regestered-members-to-be-able-to-vote-with-i-rater-script/#findComment-177180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.