I have a problem.On my site my users have some resources to do things. Let's say the resources field is called 'moves' If they go on a certain page, they get some moves deducted from them. The problem is tht if they go on that page and refresh it very fast and at the same time their 'moves' run out (insufficient funds), the page will still try to deduct the moves. Once that happens the 'moves' of that user explode to 4 trillion. The page has got limits that shouldn't make that possible (if cost of moves > moves, then it won't load). But if they click the button or refresh the page 10 times per second the page will skip that error part and still try to deduct the moves... My question is what can I do to stop the field from exploding? Could it go to 0 instead of 4 trllion? Taking out the ability to refresh or click the button many times per second is out of the question. Suggestions?
how do you store 'moves' for users? in db or somehow on client side (browser)? anyway it soundas as overflow. see warning section on www.php.net/int think you can workaround this by comparing balance and amount to deduct before real deduction
try checking the client's connection first before deducting moves using the connection_aborted() function in PHP if (!connection_aborted()) { // code goes here to deduct user moves } PHP:
mysql > ALTER TABLE table MODIFY movies INT UNSIGNED NOT NULL; This will not allow negative values in the db column.
The moves are stored in the database. But that can cause problems as well... connection aborted = when they don't let the page load entirely? That qualifies as an abort?