I have the following code:
$user_id = $_GET["user_id"];
$user = get_user_by('id',$user_id);
$balance = mycred_get_users_balance($user_id);
if ($balance > "0") {
mycred_subtract( 'Check-in',$user_id, -1, 'Checked in.' );
echo "You are checked in.";
echo ' ' . $user->first_name;
}
else{ echo "You have a balance of " . $balance . ".";
echo "<br/>";
echo "Please purchase more credits at our website freethemind.biz";
}
As part of my custom page, what I want to do is first echo the users first name based on the integer in the variable $user_id
which does not seem to echo anything at the moment.
Also, I'd like to have a timeout so that lets say if the page is visited and the user_id
is 1, the mycred_subtract
can only run once every 10 seconds or so. This will avoid the user being debited a point for multiple page requests if there was a loss of connection or something of that sort.
I'm not sure on how to implement that but what I did read was you can sleep()
but its not recommended server side.
My point is to avoid double debiting the user because of a browser deciding to send multiple requests to the webpage in a very short period of time (2-3 seconds).
EDIT
I see that it is possible to create confirm dialog box so a user can only be debited once it has been manually confirmed, would this be through the follow code:
onclick="return confirm('Are you sure?');">My Link</a>
If so, could I pass a php variable into that JavaScript, I'd like to contstruct it such that:
onclick="return confirm(' 'Check-in' . $user->first_name . '?' ');">My Link</a>