I am receiving the following error while using the php code below:
[error] 7096#0: *410 FastCGI sent in stderr: "PHP message: PHP Fatal error: Using $this when not in object context in /var/www/html_offline/core.php on line 60" while reading response header from upstream, client: [...]
I've already tried to solve this issue but couldn't find a solution.
<?php
class CORE {
private $db_sqlite;
private $db_mysql;
function __construct(){
$this->db_mysql = $this->get_MySQL();
$this->db_sqlite = $this->get_SQLite();
}
//
// MYSQL ADAPTER
//
function get_MySQL($db = null) {
if ($db == null) {
try {
$db = new PDO("mysql:host=ip_address:port;dbname=database;charset=utf8","user","password", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch(PDOException $ex) {
return $db;
}
}
return $db;
}
//
// SQLITE ADAPTER
//
function get_SQLite($db = null) {
if ($db == null) {
try {
$db = new PDO("sqlite://var/www/html_offline/ip_throttling.db", null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$db->query("CREATE TABLE IF NOT EXISTS storage (IP VARCHAR(255), TIME VARCHAR(255), ID VARCHAR(255))");
} catch(PDOException $ex) {
return $db;
}
}
return $db;
}
//
// IP QUERY RESTRICTION
//
function isThrottled($ip, $id) {
// SELECT stmt
$stmt = $this->db_sqlite->prepare('SELECT TIME FROM storage WHERE IP = :ip AND ID = :id');
$bind = array(
':ip' => $ip,
':id' => $id
);
$stmt->execute($bind);
if ($stmt->rowCount() > 0) {
$fetch = $stmt->fetch(PDO::FETCH_ASSOC);
if ($fetch['time'] <= strtotime('-30 seconds')) {
return true;
}
// DELETE stmt
$stmt = $this->db_sqlite->prepare('DELETE FROM storage WHERE IP = :ip AND ID = :id');
$stmt->execute($bind);
return false;
} else {
return false;
}
}
?>