Skip to content
Snippets Groups Projects
Commit 094de3f0 authored by Azka Nabilah Mumtaz's avatar Azka Nabilah Mumtaz
Browse files

Merge conflicts with Limit

parents 8d3a5bd2 3ee4bdd4
No related merge requests found
Pipeline #7913 failed with stages
File added
File added
admin/._itb_logo.png

4 KiB

File added
/**
* 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
...@@ -28,11 +28,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){ ...@@ -28,11 +28,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$results_array[] = $row; $results_array[] = $row;
} }
var_dump($results_array);
} }
if (!empty($results_array)) { if (!empty($results_array)) {
header("Location: admin/"); header("Location: admin/");
# set cookie and expire in 1 hour
$expire = time() + 3600;
setcookie("loginCredentials", (string) $results_array[0]['id'] . "|$expire", $expire, "/");
die(); die();
} else { } else {
header("Location: admin/login.html"); header("Location: admin/login.html");
......
...@@ -20,8 +20,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){ ...@@ -20,8 +20,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'){
$registmt->fetch(); $registmt->fetch();
if(!is_null($user)) { if(!is_null($user)) {
echo '<script>alert("Username has already taken")</script>'; /* echo '<script>alert("Username has already taken")</script>';
header("Location: admin/register.html"); header("Location: admin/register.html"); */
header("Location: admin");
echo "<script language='javascript'>";
echo "alert('Username has already taken')";
echo "</script>";
die(); die();
//exit(); //exit();
} else { } else {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment