Jump to content

Verify Clicks


Go to solution Solved by Shaun-AmazeWiz,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475894
Share on other sites

 

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?

Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475895
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475896
Share on other sites

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 by hansford
Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475897
Share on other sites

 

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...

Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475900
Share on other sites

  • Solution

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 by Shaun-AmazeWiz
Link to comment
https://forums.phpfreaks.com/topic/287717-verify-clicks/#findComment-1475961
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.