Update to support PHP 8

This commit is contained in:
Skylar Ittner 2021-11-22 18:41:45 -07:00
parent 1c725e7170
commit 97929c6731
2 changed files with 27 additions and 18 deletions

21
api.php
View File

@ -1,14 +1,17 @@
<?php
require __DIR__ . '/required.php';
use Medoo\Medoo;
header("Content-Type: application/json");
// Oldest session allowed
$session_min_date = date("Y-m-d H:i:s", strtotime("-" . SESSION_EXPIRE_MINUTES . " minutes"));
// Delete old sessions
$old_sessions = $database->select("sessions", "sid", ["timestamp[<]" => $session_min_date]);
$database->delete("scrambled_answers", ["sid" => $old_sessions]);
$database->delete("sessions", ["sid" => $old_sessions]);
foreach ($old_sessions as $sid) {
$database->delete("scrambled_answers", ["sid" => $sid]);
$database->delete("sessions", ["sid" => $sid]);
}
switch ($VARS['action']) {
case "ping":
@ -18,9 +21,9 @@ switch ($VARS['action']) {
// generate unique session ID that has an essentially zero chance of being a duplicate.
// Contains a hash of a secure random number, a hash of the user's IP, and 23 uniqid() characters.
$skey = uniqid(substr(hash("md5", mt_rand()), 3, 5) . hash("md5", getUserIP()), true);
// Image problem
//
//
// Get five random options
$answer_count = $database->count('answers');
$answers = $database->select('answers', ['aid', 'aname'], ["LIMIT" => [mt_rand(0, $answer_count - 6), 5]]);
@ -33,15 +36,15 @@ switch ($VARS['action']) {
$scrambled["real"][] = $a['aid'];
$scrambled["fake"][] = substr(hash("md5", mt_rand()), 0, 20);
}
// Text problem
//
// Get random question
$access_count = $database->count('access_questions');
$access_question = $database->select('access_questions', ['acqid', 'acqtext'], ["LIMIT" => [mt_rand(0, $access_count - 1), 1]])[0];
// Save the session data
$database->insert("sessions", ["skey" => $skey, "aid" => $correct_answer['aid'], "acqid" => $access_question['acqid'], "expired" => 0, "#timestamp" => "NOW()", "ipaddr" => getUserIP()]);
$database->insert("sessions", ["skey" => $skey, "aid" => $correct_answer['aid'], "acqid" => $access_question['acqid'], "expired" => 0, "timestamp" => Medoo::raw("NOW()"), "ipaddr" => getUserIP()]);
$sid = $database->id();
// Save the answer data
$scrambled_insert = [];
@ -49,11 +52,11 @@ switch ($VARS['action']) {
$scrambled_insert[] = ["sid" => $sid, "aid" => $scrambled['real'][$i], "acode" => $scrambled['fake'][$i]];
}
$database->insert("scrambled_answers", $scrambled_insert);
// Vary question wording a little
$questions = ["Please click on the [].", "Click the [].", "Find the []."];
shuffle($questions);
$resp = [
"session" => $skey,
"id_prefix" => substr(hash("md5", mt_rand()), 3, 5),

24
composer.lock generated
View File

@ -1,23 +1,23 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3d60b6d6d1ba750afa45d307e067f006",
"packages": [
{
"name": "catfan/medoo",
"version": "v1.4.4",
"version": "v1.7.10",
"source": {
"type": "git",
"url": "https://github.com/catfan/Medoo.git",
"reference": "bcabbef4d8355d52fc4d19f17463e5e816c9ef44"
"reference": "2d675f73e23f63bbaeb9a8aa33318659a3d3c32f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/bcabbef4d8355d52fc4d19f17463e5e816c9ef44",
"reference": "bcabbef4d8355d52fc4d19f17463e5e816c9ef44",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/2d675f73e23f63bbaeb9a8aa33318659a3d3c32f",
"reference": "2d675f73e23f63bbaeb9a8aa33318659a3d3c32f",
"shasum": ""
},
"require": {
@ -31,7 +31,7 @@
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite database",
"ext-pdo_sqlsrv": "For MSSQL database on Windows platform"
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform"
},
"type": "framework",
"autoload": {
@ -49,10 +49,11 @@
"email": "angel@catfan.me"
}
],
"description": "The lightest PHP database framework to accelerate development",
"description": "The lightweight PHP database framework to accelerate development",
"homepage": "https://medoo.in",
"keywords": [
"database",
"database library",
"lightweight",
"mariadb",
"mssql",
@ -63,7 +64,11 @@
"sql",
"sqlite"
],
"time": "2017-06-02T15:25:04+00:00"
"support": {
"issues": "https://github.com/catfan/Medoo/issues",
"source": "https://github.com/catfan/Medoo"
},
"time": "2020-02-11T08:20:42+00:00"
}
],
"packages-dev": [],
@ -73,5 +78,6 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
"platform-dev": [],
"plugin-api-version": "2.0.0"
}