aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/db.php1
-rw-r--r--lib/login.php27
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/db.php b/lib/db.php
new file mode 100644
index 0000000..6d158b7
--- /dev/null
+++ b/lib/db.php
@@ -0,0 +1 @@
+<?php $cursor = new mysqli("localhost", "loek", "", "webs"); ?>
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;