MYSQL and PHP checking if IP address is already used in order to only allow viewing page once -
the coupon should show ips haven't viewed type. if do, should echo error page. create allow user view page once.
the ip making database, php not working correctly display error page when ip found in database under type.
url: 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 coupons type = '$type' , ip = '$ip' limit 1"); if(mysql_fetch_array($resultz) !== false){ mysql_query("insert `coupons` (`id`, `type`, `ip`) values ('$randid', '$type', '$ip')"); $result = mysql_query("select * coupons 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 `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 coupon has been used.</h1> <br /> <img src='../images/logo.png' /> <br /> <p>you unable create coupon more once.</p> </div> </body> </html>"; die();}; ?>
update: had ! in if statement. able alter code allows users see page once.
i rewrite part:
$ip = $_server['remote_addr']; //if don't want every type usable once, add together ip here $resultz = mysql_query("select ip coupons type = '$type' , ip = '$ip' limit 1"); //better work num_rows here if(mysql_num_rows($resultz)>0){ mysql_query("insert `coupons` (`id`, `type`, `ip`) values ('$randid', '$type', '$ip')");
php mysql ip
No comments:
Post a Comment