darkfreaks Posted January 7, 2009 Share Posted January 7, 2009 page refreshing. okay i have a PHP game that mainly uses javascript to validate everything then switches to PHP to insert the user's score into the database and award points , however there have been complaint's of "cheating" because you can refresh the page over and over and get those points even if it starts a new game. ok here is the code. <?php $button = "<input type='submit' name='submit_Score' value='Submit Score!!'>"; if($_POST['submit_Score']){ $score = trim(strip_tags($_POST['show'])); $gameScore = $score / 4; $gameScoreFinal = round($gameScore); points("$game", "$username", "$gameScoreFinal"); $button="You have recieved <b>" . $gameScoreFinal. "</b> CP's. They have been added to your account.<br><br><center> <!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 125; google_ad_height = 125; google_ad_format = \"125x125_as\"; google_ad_type = \"text_image\"; //2007-06-08: chicka_bubblepop google_ad_channel = \"0950382107\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script><script type=\"text/javascript\"><!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 125; google_ad_height = 125; google_ad_format = \"125x125_as\"; google_ad_type = \"text_image\"; //2007-06-08: chicka_bubblepop google_ad_channel = \"0950382107\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script></center>"; } echo $button; $game_name = bubblepop; mysql_query("INSERT INTO highscores (game, user, game_name, score, daily) VALUES ('1', '$userid', '$game_name', '$score', '$datestamp')"); $x = 1; $findTop5 = mysql_query("SELECT * FROM highscores WHERE game_name = 'bubblepop' ORDER BY score DESC LIMIT 50"); while ($getTop5 = mysql_fetch_array($findTop5)) { $getUsername = fetch("SELECT username,display_name,premium,display_prem FROM members2 WHERE game = '1' AND id = '$getTop5[user]'"); if (($getUsername[premium] == 1) AND ($getUsername[display_prem])) { $getUsername[display_name] = $getUsername[display_prem]; } $top5 .= "$x. <A href=user_profile.php?game=$game&user=$getUsername[username]>$getUsername[display_name]</a> - $getTop5[score]<br>"; $x++; } $yourTotalScore = fetch("SELECT score FROM highscores WHERE game_name = 'bubblepop' AND game= '$game' AND user = '$userid'"); print "<p align=center><TABLE CELLSPACING=0 CELLPADDING=10 WIDTH=80%> <TR BGCOLOR=\"#F5E462\"> <TD> <CENTER> <B>Top Scores</B> </CENTER> </TD> </TR> <TR BGCOLOR=\"#FCFFDE\"> <TD valign=\"top\"> $top5 </TD> </TR> </TABLE></p> "; ?> Link to comment https://forums.phpfreaks.com/topic/139859-solved-stopping-page-refreshing/ Share on other sites More sharing options...
premiso Posted January 7, 2009 Share Posted January 7, 2009 Why not set session data....if the score has been submitted set a session string then check that on page load. Link to comment https://forums.phpfreaks.com/topic/139859-solved-stopping-page-refreshing/#findComment-731678 Share on other sites More sharing options...
darkfreaks Posted January 7, 2009 Author Share Posted January 7, 2009 i think i got it, the problem seems to be $_POST['show'], it seems like it needs to be set in a session to avoid refreshing. thanks Link to comment https://forums.phpfreaks.com/topic/139859-solved-stopping-page-refreshing/#findComment-731681 Share on other sites More sharing options...
premiso Posted January 7, 2009 Share Posted January 7, 2009 More like: <?php session_start(); if (isset($_SESSION['submit_score'])) die("You have already submitted."); $_SESSION['submit_score'] = $_POST['submit_score']; ?> That would work, but you may want to put the actual setting of the session in a spot past any probably errors that may occur... Link to comment https://forums.phpfreaks.com/topic/139859-solved-stopping-page-refreshing/#findComment-731685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.