From 4d0deabb161801eded085145d7b9a4e417ce81a9 Mon Sep 17 00:00:00 2001 From: posweg Date: Thu, 21 May 2020 15:57:59 +0000 Subject: [PATCH] Universal header and config link --- 404.php | 3 ++- config.php | 16 ++++++++++++++++ include/header.php | 40 ++++++++++++++++++++++++++++++++++++++++ index.php | 35 +---------------------------------- user.php | 28 +++++++++++++++++++--------- 5 files changed, 78 insertions(+), 44 deletions(-) create mode 100644 config.php create mode 100644 include/header.php diff --git a/404.php b/404.php index 2f60934..0c5be3c 100644 --- a/404.php +++ b/404.php @@ -1 +1,2 @@ -ERROR 404: Page not found + +

ERROR 404: Page not found

diff --git a/config.php b/config.php new file mode 100644 index 0000000..23d4024 --- /dev/null +++ b/config.php @@ -0,0 +1,16 @@ +logout"); + echo(" - config'"); +} +else{ + header("Location: /login"); die(); +} +?> + + +

Config

+ diff --git a/include/header.php b/include/header.php new file mode 100644 index 0000000..b1228f3 --- /dev/null +++ b/include/header.php @@ -0,0 +1,40 @@ +query("CREATE TABLE IF NOT EXISTS users( + id INTEGER PRIMARY KEY, + username TEXT, + shadow TEXT, + name TEXT, + bio TEXT + )"); + +$db->exec("CREATE TABLE IF NOT EXISTS questions( + id INTEGER PRIMARY KEY, + user INTEGER, + by INTEGER, + question TEXT, + date INTEGER, + answered INTEGER + );"); + +if(!$db->querySingle("SELECT EXISTS(SELECT * FROM users where id = 0);")){ + echo "NOTICE: anonymous user created."; + $db->exec("INSERT INTO users(id, username, name) VALUES('0','anonymous','Anonymous');"); +} + +if($_SESSION["login"] === true){ + echo("LibreCat"); + echo(" | "); + $user = $db->query("SELECT * FROM users WHERE id = ".$_SESSION["uid"].";")->fetchArray(SQLITE3_ASSOC); + echo("". $user["username"] . ""); + echo(" | "); + echo("logout"); +} +else{ + echo("Login"); + //header("Location: /login.php"); die(); +} +?> diff --git a/index.php b/index.php index 65b000f..fe6e1a2 100644 --- a/index.php +++ b/index.php @@ -1,38 +1,5 @@ query("CREATE TABLE IF NOT EXISTS users( - id INTEGER PRIMARY KEY, - username TEXT, - shadow TEXT, - name TEXT, - bio TEXT - )"); - -$db->exec("CREATE TABLE IF NOT EXISTS questions( - id INTEGER PRIMARY KEY, - user INTEGER, - by INTEGER, - question TEXT, - date INTEGER, - answered INTEGER - );"); - -if(!$db->querySingle("SELECT EXISTS(SELECT * FROM users where id = 0);")){ - echo "NOTICE: anonymous user created."; - $db->exec("INSERT INTO users(id, username, name) VALUES('0','anonymous','Anonymous');"); -} - -if($_SESSION["login"] === true){ - echo($_SESSION["uid"] . " - "); - echo("logout"); -} -else{ - echo("Login"); - //header("Location: /login.php"); die(); -} +include("include/header.php"); ?> diff --git a/user.php b/user.php index 69d7273..36db50c 100644 --- a/user.php +++ b/user.php @@ -1,12 +1,20 @@ query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC); -if(!$user || !$user["id"]){ +$p_user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC); +if(!$p_user || !$p_user["id"]){ include("404.php"); die(); } +if(isset($_SESSION["uid"])){ + if($_SESSION["uid"] == $p_user["id"]){ + $is_current_user = true; + } +} + if($validUser){ header("Location: /"); die(); } @@ -16,7 +24,7 @@ if(isset($_POST["post-submit"])){ if($_POST["post-text"] == "") $errorMsg = "The question can't be blank."; else if(strlen($_POST["post-text"]) > 400) $errorMsg = "The question can't bee longer than 400 characters"; else{ - $u = $user["id"]; + $u = $p_user["id"]; $by = 0; $question = htmlspecialchars($_POST["post-text"]); @@ -29,11 +37,13 @@ if(isset($_POST["post-submit"])){ - <?= $user["username"] ?> | LibreCat + <?= $p_user["username"] ?> | LibreCat - -

-

+ + +

+

+ config"); ?>

Ask me anything

@@ -45,7 +55,7 @@ if(isset($_POST["post-submit"])){ prepare("SELECT * FROM users WHERE id = :id"); - $qs = $db->query("SELECT * FROM questions WHERE user = '" . $user["id"] . "' LIMIT 0, 10;"); + $qs = $db->query("SELECT * FROM questions WHERE user = '" . $p_user["id"] . "' LIMIT 0, 10;"); $time = new DateTime("@0"); while($current = $qs->fetchArray(SQLITE3_ASSOC)){ @@ -53,7 +63,7 @@ if(isset($_POST["post-submit"])){ $u_prep->bindValue(":id", $current["by"], SQLITE3_INTEGER); $q_user = $u_prep->execute()->fetchArray(SQLITE3_ASSOC); - echo("

". $q_user["name"] ."

"); + echo("

". $current["id"] ." - " . $q_user["name"] ."

"); // Time $time->setTimestamp($current["date"]);