From 16a6e85b61c808dd636cc1f0a0639c896227380e Mon Sep 17 00:00:00 2001 From: freedomfeather <fadlurohmanakmal@rocketmail.com> Date: Tue, 3 Oct 2017 01:45:33 +0700 Subject: [PATCH] Menambahkan sistem logout --- login/login.php | 2 +- login/logout.php | 6 ++++++ login/sign_up.php | 3 ++- profile_page/profile.php | 11 +++++++---- template/header.php | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 login/logout.php diff --git a/login/login.php b/login/login.php index ae396437..595bfe03 100755 --- a/login/login.php +++ b/login/login.php @@ -1,4 +1,5 @@ <?php + session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!empty($_POST['user_name']) && !empty($_POST['user_password'])) { include '../database/dbconnect.php'; @@ -17,7 +18,6 @@ if($user == $dbusername && $pass == $dbpassword) { - session_start(); $_SESSION['user'] = $user; header("Location: ../order/order.php"); } diff --git a/login/logout.php b/login/logout.php new file mode 100644 index 00000000..da7dd4cf --- /dev/null +++ b/login/logout.php @@ -0,0 +1,6 @@ +<?php + session_start(); + session_unset(); + session_destroy(); + header("Location: ../login/login.html"); +?> diff --git a/login/sign_up.php b/login/sign_up.php index fc240892..2ac634cc 100644 --- a/login/sign_up.php +++ b/login/sign_up.php @@ -1,4 +1,5 @@ <?php + session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!empty($_POST['full_name']) && !empty($_POST['username']) && @@ -7,6 +8,7 @@ !empty($_POST['confirm_password']) && !empty($_POST['user_phone'])) { + session_start(); include '../database/dbconnect.php'; $fullname = $_POST['full_name']; $username = $_POST['username']; @@ -26,7 +28,6 @@ $query = mysql_query("INSERT INTO user (name,email,phone,username,password,status,pict) VALUES ('$fullname', '$email', '$phone', '$username', '$password', '$status',DEFAULT)") or die(mysql_error()); if($query) { - session_start(); $_SESSION['user'] = $username; if ($status == "customer") { header("Location: ../order/order.php"); diff --git a/profile_page/profile.php b/profile_page/profile.php index 150ea374..eaca70f4 100755 --- a/profile_page/profile.php +++ b/profile_page/profile.php @@ -1,4 +1,6 @@ -<?php //if (!isset($_SESSION['user'])) die("<br /><br />You must be logged in to view this page");?> +<?php + session_start(); +?> <html> <head> <title>U Wanna Call Me Beibh?</title> @@ -24,7 +26,8 @@ </div> <?php include '../database/dbconnect.php'; - $user = "eHower"; + + $user = $_SESSION['user']; $query=mysql_query("SELECT * FROM user WHERE username='".$user."'") or die(mysql_error()); $numrows=mysql_num_rows($query); @@ -39,9 +42,9 @@ } echo $row['email']."</br>"; echo $row['phone']."</br>"; - /*if (isset($row['pict'])) { + if (isset($row['pict'])) { echo "<script>document.getElementById('profile_pict').src = '../img/default_profile.jpeg'</script>"; - }*/ + } } } mysql_close(); diff --git a/template/header.php b/template/header.php index cf598696..57dfed50 100644 --- a/template/header.php +++ b/template/header.php @@ -4,7 +4,7 @@ <p>"An ojek for anything you need"</p></br> </div> <div class="greeting"> - <p>Hello, "Eisenhower!"</p> - <p>Logout</p> + <p>Hello, '.'"'.$_SESSION['user'].'"'.'</p> + <p><a href="../login/logout.php">Logout</a></p> </div>'; ?> -- GitLab