Shaun-AmazeWiz Posted April 12, 2014 Share Posted April 12, 2014 Okay, hello everyone, I am making a little side project at the minute but before I can really get stuck in and get cracking on it I have come into somewhat of a problem. Within my code I will be letting a user click a button as many times as they want with that they will be adding +1 to a count variable.(Each time they click their "score" will go up by 1) (Something like you would see in a little game.). Am am using jQuery to achieve this. The problem I would have is that the user could just cheat by changing the value of said variable then when it gets sent to the server it would be saved as their own value. How if possible would I go about making each click verified so to speak. Would I have to send each click to the server to be verified or is there an easier way of doing this and I just cannot see it. Hope you understand to question. Thanks -Shaun Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/ Share on other sites More sharing options...
Shaun-AmazeWiz Posted April 12, 2014 Author Share Posted April 12, 2014 I was just thinking.. Could I do something like each user that starts clicking, use a php session that creates a temp txt file on the server that also gets +1 added too it, that can be how I can verify it, would that work? Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475892 Share on other sites More sharing options...
jazzman1 Posted April 12, 2014 Share Posted April 12, 2014 I don't get it very well, so you only want to allow them to increase their values by cliking the button, right? Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475893 Share on other sites More sharing options...
Shaun-AmazeWiz Posted April 12, 2014 Author Share Posted April 12, 2014 I don't get it very well, so you only want to allow them to increase their values by cliking the button, right? Yes that is true, if i do it within a session with the txt file idea that would work wouldn't it. (if you understand what I mean), I am not the best at explain what I am trying to do sorry for that. onclick counter value = value++ when they have finished (no timer - upto the user to finish) the final value will get stored in the database Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475894 Share on other sites More sharing options...
jazzman1 Posted April 12, 2014 Share Posted April 12, 2014 if i do it within a session with the txt file idea that would work wouldn't it. I am not familiar with that, nor with clicks To the question, when the click occurred its value is sent to the server and by default it's equal to 1, if so why don't you make some validation on the server side, that the value should b explicitly equal to 1? Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475895 Share on other sites More sharing options...
Shaun-AmazeWiz Posted April 12, 2014 Author Share Posted April 12, 2014 I am not familiar with that, nor with clicks To the question, when the click occurred its value is sent to the server and by default it's equal to 1, if so why don't you make some validation on the server side, that the value should b explicitly equal to 1? Yes that could be done very easily but I would prefer if possible not too send a request to the server each time one user clicks on the button because if I said say 10 users online clicking to button pretty quickly then that's going to be a lot of requests being sent to the server. But ass well I want to user to be able to click as many times as they want on the button too. Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475896 Share on other sites More sharing options...
hansford Posted April 12, 2014 Share Posted April 12, 2014 (edited) If it's possible for the client to change the value - and how are they doing this? Anyways, it won't matter if they set it to a million clicks if each click is sent to the server and the server only registers one click per execution. $('#button').click(function() { $.ajax({ url: 'click.php', type: 'POST', data: '&click=1', dataType: 'text', success: function($data) { $('#success').html('click added to database'); }, error: function($data) { $('#success').html('error'); } }); On the server if(isset($_POST['click'])) { //no need to check post value as we //are only updating click by 1 //update user clicks in database by 1 echo 'click added!'; } Edited April 12, 2014 by hansford Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475897 Share on other sites More sharing options...
Shaun-AmazeWiz Posted April 12, 2014 Author Share Posted April 12, 2014 If it's possible for the client to change the value - and how are they doing this? Anyways, it won't matter if they set it to a million clicks if each click is sent to the server and the server only registers one click per execution. $('#button').click(function() { $.ajax({ url: 'click.php', type: 'POST', data: '&click=1', dataType: 'text', success: function($data) { $('#success').html('click added to database'); }, error: function($data) { $('#success').html('error'); } }); On the server if(isset($_POST['click'])) { //no need to check post value as we //are only updating click by 1 //update user clicks in database by 1 echo 'click added!'; } Hi hansford yes I know this could be done this way but as I said before I rather if possible do it some other way. I would prefer if possible not too send a request to the server each time one user clicks on the button because if I said say 10 users online clicking to button pretty quickly then that's going to be a lot of requests being sent to the server. I would need a way where I could add up the total clicks of a user then just send that value to the database for storing. thanks... Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475900 Share on other sites More sharing options...
Rifts Posted April 13, 2014 Share Posted April 13, 2014 wat? how are they changing the vaule? also it's fine to send the update request each time, but you could use session or some counter and only send the update request at 10 or 20 or 50 etc.. Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475939 Share on other sites More sharing options...
sKunKbad Posted April 13, 2014 Share Posted April 13, 2014 You could just encrypt/decrypt a value stored in a cookie, but sessions is the easiest solution because it keeps the value on the server. Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475941 Share on other sites More sharing options...
Solution Shaun-AmazeWiz Posted April 13, 2014 Author Solution Share Posted April 13, 2014 (edited) hey everyone, I have fixed the problem I ended up using my session idea. Each time a user clicks the button it sends a request to a page which has a session within it, the session contains a value of 0 and gets 1 added each time they have clicked the button. This also happens in jQuery so I can show the user how many clicks they have done so far. If the user leaves the page the session will be unset and also if the user wants to submit there score/clicks then this also unsets the session while adding the record to the database. - You know when you look at something you have figured out and then think, that should not have been so hard to do... Yeahhh - Thanks everyone by the way Edited April 13, 2014 by Shaun-AmazeWiz Quote Link to comment https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.