Update to support PHP 8

pull/5/head
Skylar Ittner 2 years ago
parent 1c725e7170
commit 97929c6731

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

24
composer.lock generated

@ -1,23 +1,23 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "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" "This file is @generated automatically"
], ],
"content-hash": "3d60b6d6d1ba750afa45d307e067f006", "content-hash": "3d60b6d6d1ba750afa45d307e067f006",
"packages": [ "packages": [
{ {
"name": "catfan/medoo", "name": "catfan/medoo",
"version": "v1.4.4", "version": "v1.7.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/catfan/Medoo.git", "url": "https://github.com/catfan/Medoo.git",
"reference": "bcabbef4d8355d52fc4d19f17463e5e816c9ef44" "reference": "2d675f73e23f63bbaeb9a8aa33318659a3d3c32f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/bcabbef4d8355d52fc4d19f17463e5e816c9ef44", "url": "https://api.github.com/repos/catfan/Medoo/zipball/2d675f73e23f63bbaeb9a8aa33318659a3d3c32f",
"reference": "bcabbef4d8355d52fc4d19f17463e5e816c9ef44", "reference": "2d675f73e23f63bbaeb9a8aa33318659a3d3c32f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -31,7 +31,7 @@
"ext-pdo_oci8": "For Oracle version 8 database", "ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database", "ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite 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", "type": "framework",
"autoload": { "autoload": {
@ -49,10 +49,11 @@
"email": "angel@catfan.me" "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", "homepage": "https://medoo.in",
"keywords": [ "keywords": [
"database", "database",
"database library",
"lightweight", "lightweight",
"mariadb", "mariadb",
"mssql", "mssql",
@ -63,7 +64,11 @@
"sql", "sql",
"sqlite" "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": [], "packages-dev": [],
@ -73,5 +78,6 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],
"platform-dev": [] "platform-dev": [],
"plugin-api-version": "2.0.0"
} }

Loading…
Cancel
Save