Created Custom Session System and Updated Admin Section to new System
This commit is contained in:
+9
-1
@@ -1,8 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
/*session_start();
|
||||
if (!isset($_SESSION["login"]) && $_SESSION["login"] != "true-as-hell") {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}*/
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
/*session_start();
|
||||
if (!isset($_SESSION["login"]) && $_SESSION["login"] != "true-as-hell") {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}*/
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$furatalog = new mysqli("localhost", "furatalog_admin_usr", "NR6tLk7c56bPT5[]", "furatalog");
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
/*session_start();
|
||||
if (!isset($_SESSION["login"]) && $_SESSION["login"] != "true-as-hell") {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}*/
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$_POST["nsfw"] = isset($_POST["nsfw"]) ? "1" : "0";
|
||||
|
||||
+9
-1
@@ -1,9 +1,17 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
/*session_start();
|
||||
if (!isset($_SESSION["login"]) && $_SESSION["login"] != "true-as-hell") {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}*/
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($_GET["url"])) {
|
||||
|
||||
+14
-5
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (isset($_GET["ref"])) {
|
||||
$_SESSION["ref"] = $_GET["ref"];
|
||||
@@ -7,17 +8,25 @@ if (isset($_GET["ref"])) {
|
||||
|
||||
if (isset($_POST["username"]) && isset($_POST["password"])) {
|
||||
if ($_POST["username"] == "SiskelDev" && password_verify($_POST["password"], "\$2y\$10\$uhkbDXtndzyDKsJh7d14HOBE7JoWiqYQPx3r88xDhWHnL9W4t4OJa")) {
|
||||
$_SESSION["login"] = "true-as-hell";
|
||||
$redirect = isset($_SESSION["ref"]) ? $_SESSION["ref"] : "index";
|
||||
unset($_SESSION["ref"]);
|
||||
//$_SESSION["login"] = "true-as-hell";
|
||||
$fs->setSessionData("login", "true-as-hell");
|
||||
//$redirect = isset($_SESSION["ref"]) ? $_SESSION["ref"] : "index";
|
||||
$redirect = !($fs->getSessionData("ref") == null) ? $fs->getSessionData("ref") : "index";
|
||||
//unset($_SESSION["ref"]);
|
||||
$fs->unsetSessionData("ref");
|
||||
header("Location: " . $redirect . ".php");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_SESSION["login"]) && $_SESSION["login"] == "true-as-hell") {
|
||||
/*if (isset($_SESSION["login"]) && $_SESSION["login"] == "true-as-hell") {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
}*/
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") == "true-as-hell")) {
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+7
-1
@@ -1,6 +1,12 @@
|
||||
<?php
|
||||
session_start();
|
||||
/*session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
die();*/
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
$fs->destroy();
|
||||
header("Location: login.php");
|
||||
die();
|
||||
?>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
/*session_start();
|
||||
if (isset($_SESSION["tmpdata"])) {
|
||||
$_POST["data"] = $_SESSION["tmpdata"];
|
||||
unset($_SESSION["tmpdata"]);
|
||||
@@ -10,6 +10,21 @@ if (!isset($_SESSION["login"]) && $_SESSION["login"] != "true-as-hell") {
|
||||
$_SESSION["tmpdata"] = $_POST["data"];
|
||||
header("Location: login.php?ref=redirectFromJinxxy");
|
||||
die();
|
||||
}*/
|
||||
|
||||
|
||||
require_once("/var/www/furatalog/data/script/furatalog.sessions.php");
|
||||
$fs = new furatalogSessions();
|
||||
|
||||
if (!($fs->getSessionData("tmpdata") == null) ) {
|
||||
$_POST["data"] = $fs->getSessionData("tmpdata");
|
||||
$fs->unsetSessionData("tmpdata");
|
||||
}
|
||||
|
||||
if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) {
|
||||
$fs->setSessionData("tmpdata", $_POST["data"]);
|
||||
header("Location: login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$creator_name;
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
//$fs = new furatalogSessions();
|
||||
|
||||
//$fs->setSessionData("nsfw", true);
|
||||
//$fs->getSessionData("nsfw");
|
||||
|
||||
class furatalogSessions {
|
||||
public $cookieKey = "";
|
||||
public $dataObj;
|
||||
private mysqli $db;
|
||||
private $cookie_duration = 30 * 24 * 60 * 60;
|
||||
|
||||
public function __construct() {
|
||||
$this->dataObj = (object) array();
|
||||
$this->connectDb();
|
||||
$this->getCookieKey();
|
||||
}
|
||||
|
||||
public function setSessionData($varName, $content) {
|
||||
$this->dataObj->{$varName} = $content;
|
||||
$this->saveToDb();
|
||||
$this->saveCookie();
|
||||
}
|
||||
|
||||
public function getSessionData($varName) {
|
||||
try {
|
||||
return $this->dataObj->{$varName};
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function unsetSessionData($varName) {
|
||||
unset($this->dataObj->{$varName});
|
||||
}
|
||||
|
||||
public function destroy() {
|
||||
$this->deleteData($this->cookieKey);
|
||||
$this->deleteCookie();
|
||||
}
|
||||
|
||||
private function saveToDb() {
|
||||
$jsonDataToSave = json_encode($this->dataObj, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$tmpresult = $this->db->query("SELECT cookieKey FROM `sessions` WHERE cookieKey=\"" . $randomString . "\"");
|
||||
if (!($tmpresult->num_rows > 0)) {
|
||||
$this->db->query("INSERT INTO `sessions`(`cookieKey`, `lastused`, `data`) VALUES ('" . $this->cookieKey . "', now(),'" . $jsonDataToSave . "')");
|
||||
} else {
|
||||
$this->db->query("UPDATE `sessions` SET lastused=now(), data='" . $jsonDataToSave . "' WHERE cookieKey=\"" . $this->cookieKey . "\";");
|
||||
}
|
||||
}
|
||||
|
||||
private function saveCookie() {
|
||||
setcookie("_cookieKey", $this->cookieKey, $this->cookie_duration);
|
||||
}
|
||||
|
||||
private function connectDb() {
|
||||
$this->db = new mysqli("localhost", "furatalog_admin_usr", "NR6tLk7c56bPT5[]", "furatalog");
|
||||
}
|
||||
|
||||
private function getCookieKey() {
|
||||
$this->cookieKey = isset($_COOKIE["_cookieKey"]) ? $_COOKIE["_cookieKey"] : "";
|
||||
|
||||
if ($this->cookieKey == "") {
|
||||
$this->cookieKey = generateKey();
|
||||
}
|
||||
}
|
||||
|
||||
private function getData() {
|
||||
$tmpresult = $this->db->query("SELECT id, cookieKey, UNIX_TIMESTAMP(lastused) as lastused, data FROM sessions WHERE cookieKey=\"" . $this->cookieKey . "\"");
|
||||
if ($tmpresult->num_rows > 0) {
|
||||
$fetchedData = $tmpresult->fetch_assoc();
|
||||
|
||||
if ($fetchedData["lastused"] < strtotime('-30 days')) {
|
||||
$this->deleteData($fetchedData["cookieKey"]);
|
||||
$this->deleteCookie();
|
||||
$this->getCookieKey();
|
||||
} else {
|
||||
$this->dataObj = json_decode($fetchedData["data"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteCookie() {
|
||||
setcookie("_cookieKey", "", time()-3600);
|
||||
}
|
||||
|
||||
private function deleteData($cookieKey) {
|
||||
if ($cookieKey != "" && $cookieKey != null) {
|
||||
$tmpresult = $this->db->query("DELETE FROM sessions WHERE cookieKey=\"" . $cookieKey . "\"");
|
||||
}
|
||||
}
|
||||
|
||||
private function generateKey() {
|
||||
$isNotInDB = false;
|
||||
|
||||
do {
|
||||
$length = 20;
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
$tmpresult = $this->db->query("SELECT cookieKey FROM `sessions` WHERE cookieKey=\"" . $randomString . "\"");
|
||||
if (!($tmpresult->num_rows > 0)) {
|
||||
$isNotInDB = true;
|
||||
}
|
||||
} while (!$isNotInDB);
|
||||
|
||||
return $randomString;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user