Jump to content

Recommended Posts

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 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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.