Created
July 12, 2020 19:38
-
-
Save obhy08/1771e296cec51e5e496133029f4f938a to your computer and use it in GitHub Desktop.
Login Hak Akses OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$page = (isset($_GET['page']))? $_GET['page'] : ''; | |
if(isset($_SESSION['username'])){ // Jika sudah login | |
if($_SESSION['role'] == 'admin'){ // Jika user yang login adalah admin | |
// Berikut halaman yang bisa di akses : | |
switch($page){ | |
case 'login': // $page == login (jika isi dari $page adalah home) | |
include "views/login.php"; // load file login.php yang ada di folder views | |
break; | |
case 'home': // $page == home (jika isi dari $page adalah home) | |
include "views/home.php"; // load file home.php yang ada di folder views | |
break; | |
default: // Ini untuk set default jika isi dari $page tidak ada | |
// Set halaman 404 Not Found | |
header("HTTP/1.0 404 Not Found"); | |
echo "<h1>404 Not Found</h1>"; | |
echo "The page that you have requested could not be found."; | |
exit(); | |
} | |
}else{ // Jika user yang login adalah operator | |
// Berikut halaman yang bisa di akses : | |
switch($page){ | |
case 'login': // $page == login (jika isi dari $page adalah home) | |
include "views/login.php"; // load file login.php yang ada di folder views | |
break; | |
case 'home': // $page == home (jika isi dari $page adalah home) | |
include "views/home.php"; // load file home.php yang ada di folder views | |
break; | |
default: // Ini untuk set default jika isi dari $page tidak ada | |
// Set halaman 404 Not Found | |
header("HTTP/1.0 404 Not Found"); | |
echo "<h1>404 Not Found</h1>"; | |
echo "The page that you have requested could not be found."; | |
exit(); | |
} | |
} | |
}else // Jika belum login | |
include "views/login.php"; // Set default halamannya adalah "login" | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); // Start session nya | |
// Kita cek apakah user sudah login atau belum | |
// Cek nya dengan cara cek apakah terdapat session username atau tidak | |
if(isset($_SESSION['username'])){ // Jika session username ada berarti dia sudah login | |
include "layouts/backend.php"; // Kita panggil template backend | |
}else{ // Jika user belum login | |
include "layouts/login.php"; // Kita panggil template login | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- phpMyAdmin SQL Dump | |
-- version 4.7.0 | |
-- https://www.phpmyadmin.net/ | |
-- | |
-- Host: 127.0.0.1 | |
-- Generation Time: Jul 11, 2020 at 03:01 AM | |
-- Server version: 10.1.25-MariaDB | |
-- PHP Version: 5.6.31 | |
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | |
SET AUTOCOMMIT = 0; | |
START TRANSACTION; | |
SET time_zone = "+00:00"; | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8mb4 */; | |
-- | |
-- Database: `loginoop` | |
-- | |
-- -------------------------------------------------------- | |
-- | |
-- Table structure for table `user` | |
-- | |
CREATE TABLE `user` ( | |
`id` int(11) NOT NULL, | |
`username` varchar(20) NOT NULL, | |
`password` varchar(50) NOT NULL, | |
`nama` varchar(200) NOT NULL, | |
`role` enum('admin','operator') NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
-- | |
-- Dumping data for table `user` | |
-- | |
INSERT INTO `user` (`id`, `username`, `password`, `nama`, `role`) VALUES | |
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'A4U Official Admin', 'admin'), | |
(2, 'operator', '4b583376b2767b923c3e1da60d10de59', 'A4U Official Operator', 'operator'); | |
-- | |
-- Indexes for dumped tables | |
-- | |
-- | |
-- Indexes for table `user` | |
-- | |
ALTER TABLE `user` | |
ADD PRIMARY KEY (`id`); | |
-- | |
-- AUTO_INCREMENT for dumped tables | |
-- | |
-- | |
-- AUTO_INCREMENT for table `user` | |
-- | |
ALTER TABLE `user` | |
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;COMMIT; | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment