My question is very simple i'm programming some sort of an earning site and what i want to add to my php is:
when the user type the captcha wrong , number of user coins doesn't increase or decrease but when he types it right , it increases by 100
but the problem i faced is that however the user types it right it doesn't increase after the first time i mean it doesn't go to 200 or more .. and when he types it wrong it turns back into 0 again note: i'm using solve media for the captcha service
this is my code
$current n = 0;
if (!$solvemedia_response->is_valid) {
print "<div class='alert alert-danger'> Captcha wrong try again!: ".$solvemedia_response->error."</div>";
$currentn +=0;
echo $currentn;
}else {
print "<div class='alert alert-success'> 100 satoshis have been earned successfuly </div>";
$currentn +=100;
echo $currentn;
}
You're not storing the value anywhere. All the code ever does is declare a variable to 0 and then maybe add 100 to it. So all the variable will ever be is 0 or 100.
Persist the value somewhere. For example, in session state. Something like this:
$currentn = 0;
if (isset($_SESSION['currentn'])) {
$currentn = $_SESSION['currentn'];
}
And when you set the value:
$currentn += 100;
$_SESSION['currentn'] = $currentn;
You can refactor where you store and retrieve session data depending on how you want to organize your code. But the point is that you need to store the value somewhere. Otherwise every time you load the page it starts again at zero.
Edit: I almost forgot, in PHP you also need to start the session service manually before using it. So at the top of any script that uses it you’d need this:
session_start();