// when it has been incremented to 102, it has reached
// 100 reqs
if($inc>=102){
// reached limit, delete and give captcha
apcu_delete($_COOKIE["pass"]);
}else{
// the cookie is OK! dont die() and give results
if($output===true){
$frontend->loadheader(
$get,
$filters,
$page
);
}
return;
}
}
}
if($output===false){
echojson_encode([
"status"=>"The \"pass\" token in your cookies is missing or has expired!!"
]);
die();
}
/*
Validateformdata
*/
$lines=
explode(
"\r\n",
file_get_contents("php://input")
);
$invalid=false;
$answers=[];
$key=false;
$error="";
foreach($linesas$line){
$line=explode("=",$line,2);
if(count($line)!==2){
$invalid=true;
break;
}
preg_match(
'/^c\[([0-9]+)\]$/',
$line[0],
$regex
);
if(
$line[1]!="on"||
!isset($regex[0][1])
){
// check if its k
if(
$line[0]=="k"&&
strpos($line[1],"c.")===0
){
$key=apcu_fetch($line[1]);
apcu_delete($line[1]);
}
break;
}
$regex=(int)$regex[1];
if(
$regex>=16||
$regex<=-1
){
$invalid=true;
break;
}
$answers[]=$regex;
}
if(
!$invalid&&
$key!==false
){
$check=$key[1];
// validate answer
for($i=0;$i<count($key[0]);$i++){
if(!in_array($i,$answers)){
continue;
}
if($key[0][$i][0]==$key[2]){
$check--;
}else{
// got a wrong answer
$check=-1;
break;
}
}
if($check===0){
// we passed the captcha
// set cookie
$inc=apcu_inc("cookie");
$chars=
array_merge(
range("A","Z"),
range("a","z"),
range(0,9)
);
$c=count($chars)-1;
$key="c".$inc.".";
for($i=0;$i<20;$i++){
$key.=$chars[random_int(0,$c)];
}
apcu_inc($key,1,$stupid,86400);
setcookie(
"pass",
$key,
[
"expires"=>time()+86400,// expires in 24 hours
"samesite"=>"Strict",
"path"=>"/"
]
);
$frontend->loadheader(
$get,
$filters,
$page
);
return;
}else{
$error="<div class=\"quote\">You were <a href=\"https://www.youtube.com/watch?v=e1d7fkQx2rk\" target=\"_BLANK\" rel=\"noreferrer nofollow\">kicked out of Mensa.</a> Please try again.</div>";