Jump to content


Photo

How do i stop Refreshers


  • Please log in to reply
1 reply to this topic

#1 lama16

lama16
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 March 2006 - 12:24 AM

Hi i would like to stop user refreshing on the same page...
I have this game which when the user loses in an attack the user could keep on refreshing the page till the opponents hp is 0 and then he would win the fight. so what i want to do is when the user trys to refresh a message would say that he cannot refresh that page or something.

below is the code of what i have so far... sorry its a bit mess and long..

<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm,0);
$_GET['ID'] == (int) $_GET['ID'];
if(!$_GET['ID'])
{
print "WTF you doing, bro?";
$h->endpage();
exit;
}
else if($_GET['ID'] == $userid)
{
print "Only the crazy attack themselves";
$h->endpage();
exit;
}
//get player data
$youdata=$ir;
$q=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}",$c);
$odata=mysql_fetch_array($q);
if($odata['hp'] == 1)
{
print "This player is unconscious.<br />
<a href='index.php'>&gt; Back</a>";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($odata['hospital'] and $ir['hospital']==0)
{
print "This player is in hospital.<br />
<a href='index.php'>&gt; Back</a>";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($odata['fedjail'] == 1)
{
print "The other person is in fed!<br />
<a href='index.php'>&gt; Back</a>";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($ir['hospital'] and !$odata['hospital'])
{
print "Stop trying to attack other people your in hospital.<br />
<a href='hospital.php'>&gt; Back</a>";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
print "<table width=100%><tr><td colspan=2 align=center>";
if($_GET['wepid'])
{
if($_SESSION['attacking']==0)
{
if ($youdata['energy'] >= $youdata['maxenergy']/2)
{

$youdata['energy']-= $youdata['maxenergy']/2;
$me=$youdata['maxenergy']/2;
mysql_query("UPDATE users SET energy=energy- {$me} WHERE userid=$userid",$c);
$_SESSION['attacklog']="";
}
else
{
print "You can only attack someone when you have 50% energy";
$h->endpage();
exit;
}
}
$_SESSION['attacking']=1;
$_GET['wepid'] = (int) $_GET['wepid'];
$_GET['nextstep'] = (int) $_GET['nextstep'];

//damage
$qr=mysql_query("SELECT * FROM inventory WHERE inv_itemid={$_GET['wepid']} and inv_userid=$userid",$c);
if(mysql_num_rows($qr)==0)
{
print "Stop trying to abuse a game bug. You can lose all your EXP for that.<br />
<a href='index.php'>&gt; Home</a>";
mysql_query("UPDATE users SET exp=0 where userid=$userid",$c);
die("");
}
$qo=mysql_query("SELECT i.*,w.* FROM items i LEFT JOIN weapons w ON i.itmid=w.item_id WHERE w.item_id={$_GET['wepid']}",$c);
$r1=mysql_fetch_array($qo);
$mydamage=(int) (($r1['damage']*$youdata['strength']/$odata['guard'])*(rand(8000,12000)/10000));
$hitratio=min(50*$ir['agility']/$odata['agility'],95);
if($userid==1) { $hitratio=100; }
if(rand(1,100) <= $hitratio)
{
$q3=mysql_query("SELECT a.Defence FROM inventory iv LEFT JOIN items i ON iv.inv_itemid = i.itmid LEFT JOIN armour a ON i.itmid=a.item_ID WHERE i.itmtype=7 AND iv.inv_userid={$_GET['ID']} ORDER BY rand()", $c);
if(mysql_num_rows($q3))
{
$mydamage-=mysql_result($q3,0,0);
}
if($mydamage < 1) { $mydamage=1; }
$odata['hp']-=$mydamage;
if($odata['hp']==1) { $odata['hp']=0;$mydamage+=1; }
mysql_query("UPDATE users SET hp=hp-$mydamage WHERE userid={$_GET['ID']}",$c);
print "<font color=red>{$_GET['nextstep']}. Using your {$r1['itmname']} you hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</font><br />\n";
$_SESSION['attacklog'].="<font color=red>{$_GET['nextstep']}. Using his {$r1['itmname']} {$ir['username']} hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</font><br />\n";
}
else
{
print "<font color=red>{$_GET['nextstep']}. You tried to hit {$odata['username']} but missed ({$odata['hp']})</font><br />\n";
$_SESSION['attacklog'].="<font color=red>{$_GET['nextstep']}. {$ir['username']} tried to hit {$odata['username']} but missed ({$odata['hp']})</font><br />\n";
}
if($odata['hp'] <= 0)
{
$odata['hp']=0;
$_SESSION['attackwon']=$_GET['ID'];
mysql_query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}",$c);
print "<form action='attackleave.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Leave Them' /></form>
<form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Mug Them' /></form>
<form action='attackhosp.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Hospitalize Them' /></form>";
}
else {
//choose opp gun
$eq=mysql_query("SELECT iv.*,i.*,w.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid LEFT JOIN weapons w ON iv.inv_itemid=w.item_id WHERE iv.inv_userid={$_GET['ID']} AND ( i.itmtype=3 OR i.itmtype=4 )",$c);
if(mysql_num_rows($eq) == 0)
{
$wep="Fists";
$dam=(int)((((int) ($odata['strength']/100)) +1)*(rand(8000,12000)/10000));
}
else
{
$cnt=0;
while($r=mysql_fetch_array($eq))
{
$enweps[]=$r;
$cnt++;
}
$weptouse=rand(0,$cnt-1);
$wep=$enweps[$weptouse]['itmname'];
$dam=(int) (($enweps[$weptouse]['damage']*$odata['strength']/$youdata['guard'])*(rand(8000,12000)/10000));
}
$hitratio=min(50*$odata['agility']/$ir['agility'],95);
if($odata['userid']==1) { $hitratio=100; }
if(rand(1,100) <= $hitratio)
{
$q3=mysql_query("SELECT a.Defence FROM inventory iv LEFT JOIN items i ON iv.inv_itemid = i.itmid LEFT JOIN armour a ON i.itmid=a.item_ID WHERE i.itmtype=7 AND iv.inv_userid=$userid ORDER BY rand()", $c);
if(mysql_num_rows($q3))
{
$dam-=mysql_result($q3,0,0);
}
if($dam < 1) { $dam=1; }
$youdata['hp']-=$dam;
mysql_query("UPDATE users SET hp=hp-$dam WHERE userid=$userid",$c);
$ns=$_GET['nextstep']+1;
print "<font color=blue>{$ns}. Using his $wep {$odata['username']} hit you doing $dam damage ({$youdata['hp']})</font><br />\n";
$_SESSION['attacklog'].="<font color=blue>{$ns}. Using his $wep {$odata['username']} hit {$ir['username']} doing $dam damage ({$youdata['hp']})</font><br />\n";
}
else
{
$ns=$_GET['nextstep']+1;
print "<font color=blue>{$ns}. {$odata['username']} tried to hit you but missed ({$youdata['hp']})</font><br />\n";
$_SESSION['attacklog'].="<font color=blue>{$ns}. {$odata['username']} tried to hit {$ir['username']} but missed ({$youdata['hp']})</font><br />\n";
}
if($youdata['hp'] <= 0)
{
$youdata['hp']=0;
mysql_query("UPDATE users SET hp=0 WHERE userid=$userid",$c);
print "<form action='attacklost.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Continue' />";
}
}
}
else if ($odata['hp'] < $odata['maxhp']/2)
{
print "You can only attack those who have at least 1/2 their max health";
$h->endpage();
exit;
}
else if ($ir['gang'] == $odata['gang'] && $ir['gang'] > 0)
{
print "You are in the same gang as {$odata['username']}! What are you smoking today dude!";
$h->endpage();
exit;
}
else if ($youdata['energy'] < $youdata['maxenergy']/2)
{
print "You can only attack someone when you have 50% energy";
$h->endpage();
exit;
}
else if ($youdata['location'] != $odata['location'])
{
print "You can only attack someone in the same location!";
$h->endpage();
exit;
}
else if ($odata['hospital'] > 0)
{
print "Let him rest!";
$h->endpage();
exit;
}
else
{
}
print "</td></tr>";
if($youdata['hp'] <= 0 || $odata['hp'] <= 0)
{
print "</table>";
}
else
{
print "<tr><td>Your Health: {$youdata['hp']}/{$youdata['maxhp']}</td><td>Opponents Health: {$odata['hp']}/{$odata['maxhp']}</td></tr>";
$mw=mysql_query("SELECT iv.*,i.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid WHERE iv.inv_userid=$userid AND (i.itmtype = 3 || i.itmtype = 4)",$c);
print "<tr><td colspan=2 align='center'>Attack with:<br />";
while($r=mysql_fetch_array($mw))
{
if(!$_GET['nextstep']) { $ns=1; } else { $ns=$_GET['nextstep']+2; }
print "<a href='attack.php?nextstep=$ns&amp;ID={$_GET['ID']}&amp;wepid={$r['itmid']}'>{$r['itmname']}</a><br />";
}
print "<br /><br /><br /><a href='attacksuicide.php?ID={$_GET['ID']}'><b>Commit Suicide!!!</b></a><br />";
print "</table>";
}
$h->endpage();
?>


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 March 2006 - 01:05 AM

If a user refresh the page does an entry go into the database or is it a counter that automatickly updates on refresh.

if it is a database entry heres an example that the insert wont happenn untill a user press a button.
if (isset($_POST['client']))
{
$sql = "INSERT INTO jobs (client, jobdesc, workdesc, result) VALUES ('$client','$jobdesc','$workdesc','$result')";
$result = mysql_query($sql);
$_POST = array();
}
else
{
?>
<form name=form method="post" action="<?php echo $PHP_SELF?>" onSubmit="return verify();">
{contents of form}</form>

or this way if database driven


The solution was to create a new datetime column in the relevant table and input a hidden (time) field in the form:
<INPUT TYPE='hidden' NAME='time' VALUE='<? echo date("YmdHis"); ?>'>


After form submission read the last entered datetime from the database and compare with $time. Actually this didn't work. I had to create another hidden field $time1 which was formatted exactly the same as MySQL stores the datetime type. ie

<INPUT TYPE='hidden' NAME='time1' VALUE='<? echo date("Y-m-d H:i:s"); ?>'>

Then compare the last submit_time to the database with the current $time1. If they are the same then the script redirects you to the original form:



$sql = mysql_query("SELECT submit_time FROM jobs ORDER BY jobid DESC LIMIT 1",$db);
$submit = mysql_result($sql,0,0);
if((isset($_POST['client'])) && ($submit != $_POST['time1']))
{
//INSERT to database
}
else
{
?>
//process form
<?
}
?>
The form is only processed if the times are different...
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users