Welcome to the Browser-Base Game Zone forums!
$userquery = mysql_query ("SELECT level FROM users WHERE userid=$playerid LIMIT 1");$cityquery = mysql_query ("SELECT citylevel FROM cities WHERE cityid=$id LIMIT 1"); // the $id being what is passed from the querystring, you should of course sanitize/check before executing the query$userlevel = mysql_fetch_assoc($userquery); // retrieve level of user$citylevel = mysql_fetch_assoc($cityquery); // retrieve level of city// Edit you can even add more checks here likeif (empty($citylevel)) { die(" This city doesn't exist !!"); }if ($userlevel['level'] >= $citylevel['citylevel']) {// process code to move user}else {// display error}
If ($player->City_ID == $cityid) { include("templates/private_header.php"); echo "Are you high? You're already here moron<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; }
If ($player->Level < $buscost1['Level']) { // Check that there is a method to retrieve the level before... include("templates/private_header.php"); echo "You can't access this city<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; }
Ok after looking at the source code it's easy to do, note that as i don't know the way your database is setup i am going to put some arbitrary value in there... this code will not work as is you have to mod it of course.1) change $query = $db->execute("select `City_ID`, `City_Name`, `Cost` from `Cities` where `City_ID`=?", array($_GET['id']));with $query = $db->execute("select `City_ID`, `City_Name`, `Cost`, `Level` from `Cities` where `City_ID`=?", array($_GET['id']));(check that there is a Field "Level" in the table Cities, and if it's another name, change the code accordingly)2) add before thisCode: [Select]If ($player->City_ID == $cityid) { include("templates/private_header.php"); echo "Are you high? You're already here moron<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; }the following code :Code: [Select]If ($player->Level < $buscost1['Level']) { // Check that there is a method to retrieve the level before... include("templates/private_header.php"); echo "You can't access this city<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; }
$query = $db->execute("select `City_ID`, `City_Name`, `Cost`, `Minimum_Level` from `Cities` where `City_ID`=?", array($_GET['id']));while ($buscost1 = $query->fetchrow()) {$buscost2 = $buscost1['Cost'];$citylvl = $buscost1['Minimum_Level'];$cityID = $buscost1['City_ID'];}if ($_GET['act'] == "go") { if (empty($cityID) ) { include("templates/private_header.php"); echo "This city doesn't exist duh duh duh !!<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; } if ($player->Level < $citylvl) { // Check that there is a method to retrieve the level before... include("templates/private_header.php"); echo "You can't access this city<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; } if ($player->gold < $buscost2) { include("templates/private_header.php"); echo "Hey everyone look, this wanna be gansta thinks this bus is free!<p>"; echo "<a href=\"home.php\">Home</a>\n"; include("templates/private_footer.php"); exit; }// continue process here
whatever you do post or query string people will still be able to hijack your forms to change location and whatnot.What you need to do is that you check that the item belongs to the right shop, and to do so a fast query to check that the ID of the item is in the right table for the right shop id and you are set, if the result is null/empty then the guy tries to cheat .Tell me are you using this on a production game or just a test game ?
$queryshop = $db->execute("SELECT * FROM Shops Where $player->City_ID = Shop_City_ID");echo "Here are the shopping areas available here.<p>";echo "<table width=\"100%\" border=\"1\">\n";echo "<th width=\"199\" class=\"cellheader\">Shop</th>";echo "<th width=\"217\" class=\"cellheader\">Description</th>";while ($getshops = $queryshop->fetchrow()){echo "";echo "<tr>";echo "<td width=\"199\"><a href='shop3.php?act=go&id={$getshops['Shop_ID']}'>{$getshops['Shop_Name']}</a></td>\n";echo "<td width=\"217\">";echo "{$getshops['Shop_Description']}";echo "</td>\n";echo "</tr>\n";}echo "</table>\n";
if ($_GET['act'] == go){ $shopid = $_GET['id'];$getstuff = $db->execute("SELECT * FROM blueprint_items Where $shopid = BP_Shop_ID");while ($item = $getstuff->fetchrow()){ echo "<fieldset>\n"; echo "<legend><b>" . $item['name'] . "</b></legend>\n"; echo "<table width=\"100%\">\n"; echo "<tr><td width=\"17%\"><image src='$item[Item_Image]' alt='item' /></td>\n"; echo "<td width=\"59%\">"; echo $item['description'] . "\n<br /><br />"; echo "<b>Effectiveness:</b> " . $item['effectiveness'] . "\n"; echo "</td><td width=\"24%\">"; echo "<b>Price:</b> " . $item['price'] . "<br />"; echo "<a href=\"shop3.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />"; echo "</td></tr>\n"; echo "</table>"; echo "</fieldset>\n<br />"; }}
if ($get('act') == buy {
$queryshop = $db->execute("SELECT * FROM Shops Where $player->City_ID = Shop_City_ID");
$query = $db->execute("select `id`, `name`, `price`, `Item_Image` from `blueprint_items` where `id`=?", array($_GET['id']));
I hesitate to suggest it but it seems so simple....why not add the shop id to your second statement. Then you don't need the first one...something like the following:$query = $db->execute("select `id`, `name`, `price`, `Item_Image` from `blueprint_items` inner join Shops on Shops.shop_id = blueprint_items.shop_id where Shops.Shop_city_id = $player->Shop_City_ID and `id`=?", array($_GET['id']));alternatively:select id, name, price, Item_Imagefrom blueprint_itemsinner join Shops on Shops.shop_id = blueprint_items.shop_id where Shops.shop_city_id = $player->City_IDand id = $_GET['id'];My 2 cents...hope it helps.