diff --git a/._dbConnect.php b/._dbConnect.php new file mode 100644 index 0000000000000000000000000000000000000000..882a3b5b8d0a7d1f963da5aded6cfc94a9052d9d Binary files /dev/null and b/._dbConnect.php differ diff --git a/admin/._akun.html b/admin/._akun.html new file mode 100644 index 0000000000000000000000000000000000000000..e372bfb52d33cede477643b398c74e288f006e1d Binary files /dev/null and b/admin/._akun.html differ diff --git a/admin/._itb_logo.png b/admin/._itb_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..c269bad6837b2028d672cad640fdce99b309e9ee Binary files /dev/null and b/admin/._itb_logo.png differ diff --git a/admin/._kegiatan.html b/admin/._kegiatan.html new file mode 100644 index 0000000000000000000000000000000000000000..faf4b21cb738c0f32cadff062fbc12c4c85671ea Binary files /dev/null and b/admin/._kegiatan.html differ diff --git a/cookie_checking.php b/cookie_checking.php new file mode 100644 index 0000000000000000000000000000000000000000..114baadeef5ecce53910eb7141945bf56dfff247 --- /dev/null +++ b/cookie_checking.php @@ -0,0 +1,56 @@ +/** + * Created by PhpStorm. + * User: kevin + * Date: 2/1/2019 + * Time: 4:17 PM + */ + +<?php +/** + * Created by PhpStorm. + * User: kevin + * Date: 10/22/2018 + * Time: 10:47 PM + */ + +require "dbConnect.php"; +#Cookie Checking, Expire -> Redirect to Login, Not set -> Redirect to Login +if(isset($_COOKIE["loginCredentials"] )){ + # Already set + list($idUser,$expire) = explode("|",$_COOKIE["loginCredentials"]); + if ($expire < time()){ + #Expire + unset($_COOKIE['loginCredentials']); + setcookie('loginCredentials','',time()-3600,"/"); + header("Location: admin/login.html"); + die(); + } + else { + $stmt = $conn -> prepare('SELECT * FROM `user` WHERE id = ?'); + if (!$stmt) { + echo $conn->error; + return; + } + $stmt->bind_param("s", $idUser); + $stmt->execute(); + $result = $stmt->get_result(); + $results_array = array(); + while ($row = $result->fetch_assoc()) { + $results_array[] = $row; + } + + if (empty($results_array)){ + #User invalid + unset($_COOKIE['loginCredentials']); + setcookie('loginCredentials','',time()-3600,"/"); + header("Location: admin/login.html"); + die(); + } + } +}else{ + #Not set + unset($_COOKIE['loginCredentials']); + setcookie('loginCredentials','',time()-3600,"/"); + header("Location: admin/login.html"); + die(); +} \ No newline at end of file diff --git a/login_process.php b/login_process.php index 54867d51183967d49b42783d9cca252d96771ea2..e4fa2eae930721e9f0d85ad2b5b6d123b82a48d6 100644 --- a/login_process.php +++ b/login_process.php @@ -28,11 +28,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){ while ($row = $result->fetch_assoc()) { $results_array[] = $row; } - var_dump($results_array); } if (!empty($results_array)) { header("Location: admin/"); + # set cookie and expire in 1 hour + $expire = time() + 3600; + setcookie("loginCredentials", (string) $results_array[0]['id'] . "|$expire", $expire, "/"); die(); } else { header("Location: admin/login.html"); diff --git a/register.php b/register.php index 5b759d0d51b5262b4cba5f6643b51eb3da9dffaf..1da6ad6b2217ff7d25a7e0f7940d8b05ae144a8f 100644 --- a/register.php +++ b/register.php @@ -20,8 +20,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){ $registmt->fetch(); if(!is_null($user)) { - echo '<script>alert("Username has already taken")</script>'; - header("Location: admin/register.html"); + /* echo '<script>alert("Username has already taken")</script>'; + header("Location: admin/register.html"); */ + header("Location: admin"); + echo "<script language='javascript'>"; + echo "alert('Username has already taken')"; + echo "</script>"; die(); //exit(); } else {