aboutsummaryrefslogtreecommitdiff
path: root/lib/login.php
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-05-09 14:50:10 +0200
committerlonkaars <loek@pipeframe.xyz>2023-05-09 14:50:10 +0200
commit07d9bcf6b55a7aa866397def09c300347d9c88ea (patch)
treeb7734f271aba677228300eebd732e41302692c84 /lib/login.php
parent6d5c72f908e8f7c1c2b0defa696aad43c55fc1ba (diff)
WIP show cart count
Diffstat (limited to 'lib/login.php')
-rw-r--r--lib/login.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/login.php b/lib/login.php
index 3467994..39dc612 100644
--- a/lib/login.php
+++ b/lib/login.php
@@ -1,13 +1,34 @@
<?php
+$username = $_COOKIE['username'];
+$password = $_COOKIE['password'];
+
+function login($username, $password) {
+ if (!$username) return false;
+ if (!$password) return false;
+ return true;
+}
+
function check_login() {
- if(!isset($_COOKIE['username'])) return false;
- if(!isset($_COOKIE['password'])) return false;
+ global $username, $password;
+ if (!login($username, $password)) return false;
return true;
}
+require_once "../lib/db.php";
+function get_cart_count() {
+ global $username, $cursor;
+ $statement = $cursor->prepare("select sum(cart.count) as count from cart join customer on customer.id = cart.customer join product on product.id = cart.product where customer.name = ?");
+ $statement->bind_param("s", $username);
+ if (!$statement->execute()) return 0;
+ $res = $statement->get_result();
+ if (!mysqli_num_rows($res)) return 0;
+ $obj = $res->fetch_object();
+ return $obj->count;
+}
+
$logged_in = check_login();
-$cart_count = 0;
+$cart_count = get_cart_count();
function if_logged_in($is, $redirect, $back = false) {
global $logged_in;