php - jquery check ip before doing rest of stuff -
hey all, have jquery script that's pretty fun game, can view here link text.
now after play button clicked, send users ip via ajax see if matches ip stored site. if rest of action performed. i'm having trouble getting 1st ajax work. here's script.
var hitcount = 0, misscount = 0; function isnumeric(n) { return !isnan(n); } $("#getit").click(function() { var hitcount = 0, misscount = 0; $('#hitcount').text(0); $('#misscount').text(0); /* ajax check ip goes here if successful below performed*/ $('#message').hide(100); var li = [], intervals = 0, n = parseint($('#mynumber').val()); var intervalid = -1; if (isnumeric(n)) { intervalid = setinterval(function() { li[intervals++ % li.length].text(math.random() > .1 ? math.floor(math.random() * (10 + n) + (n / 2)) : n).attr('class', ''); }, <?php echo $time ?>); } $('#randomnumber').empty(); (var = 0; < 7; i++) { li.push($('<li />').appendto('#randomnumber')); } $('#randomnumber').delegate("li", "click", function() { var $this = $(this); if (!$this.hasclass('clicked')) { if (parseint($this.text(), 10) === n) { $this.addclass('correct'); $('#hitcount').text(++hitcount); } else { $this.addclass('wrong'); $('#misscount').text(++misscount); } //new code if misscount > 3 stop game , save value if(misscount>=2){ clearinterval(intervalid); $('#randomnumber').undelegate("li", "click"); // use ajax request save values $.ajax({ type : 'post', url : 'fbhighscore_hwnd.php', datatype : 'json', data: { tgameid: $('#tgameid').val(),mynumber: $('#mynumber').val(),totalhits: hitcount }, success : function(data){ $('#waiting').hide(500); $('#message').removeclass().addclass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500); if (data.error === true) $('#loginform').show(500); else $('#send').hide(500); }, error : function(xmlhttprequest, textstatus, errorthrown) { $('#waiting').hide(500); $('#message').removeclass().addclass('error') .text('there error.').show(500); $('#loginform').show(500); } }); } } $this.addclass('clicked'); }); return false; });
in php file in ajax post validate ip against users ip such as... if($_server['remote_addr'] == $user_ip)) { //do stuff }
Comments
Post a Comment