优惠券只应显示尚未查看该类型的IP。如果他们这样做,它应该回显错误页面。只允许用户查看一次页面。
IP正在进入数据库,但是当在该类型下的数据库中找到IP时,PHP无法正常显示错误页面。
网址:http://muhs.trinix.co/coupon?type=czo0OiJNZW93Ijs=
<?PHP
if(empty($_GET['type'])){die();}
mysql_connect("localhost", "muhs_cp", "********************");
mysql_select_db("muhs_cp");
$type = mysql_real_escape_string(unserialize(base64_decode($_GET['type'])));
$randid = rand(1, 9999999999);
$ip = $_SERVER['REMOTE_ADDR'];
$resultz = mysql_query("SELECT ip FROM coupons WHERE type = '$type' AND ip = '$ip' LIMIT 1");
if(mysql_fetch_array($resultz) !== false){
mysql_query("INSERT INTO `coupons` (`id`, `type`, `ip`) VALUES ('$randid', '$type', '$ip')");
$result = mysql_query("SELECT * FROM coupons WHERE type = '".mysql_real_escape_string($type)."'") or die(mysql_error());
$row = mysql_fetch_array( $result );
$expired = $row['expired'];
$notes = $row['notes'];
$cookie = $row['cookie'];
mysql_query("UPDATE `totals` SET `number` = `number` + 1 WHERE `type` = '".mysql_real_escape_string($type)."'");
}
else{
echo "
<html>
<head>
<title>Your Coupon</title>
<link href='css/screen.css' rel='stylesheet' type='text/css' />
</head>
<body id='wrapper'>
<div id='login'>
<h1>Whoops! Looks like this coupon has already been used.</h1>
<br />
<img src='../images/logo.png' />
<br />
<p>You are unable to make a coupon more than once.</p>
</div>
</body>
</html>"; die();};
?>
更新:我有一个额外的!在if语句中。此外,我能够更改代码,以便它只允许用户查看一次页面。
答案 0 :(得分:0)
就在这一行:
if(mysql_fetch_array($resultz) !== false){ ...
如果不应该返回某些内容,那么你应该说!= NULL。你拥有它的方式永远是!== false所以它永远不会显示作为else语句一部分的页面,因为它永远不会那么远。
例如,
如果你想做A,只有当B处于状态C时,对我们而言,数据库中没有IP。