· 6 years ago · Aug 21, 2019, 02:02 PM
1-- Dumping database structure for tes_db
2CREATE DATABASE IF NOT EXISTS `tes_db` /*!40100 DEFAULT CHARACTER SET latin1 */;
3USE `tes_db`;
4
5
6-- Dumping structure for table tes_db.karyawan
7CREATE TABLE IF NOT EXISTS `karyawan` (
8 `id_karyawan` int(10) NOT NULL AUTO_INCREMENT,
9 `pass_karyawan` varchar(50) NOT NULL DEFAULT '0',
10 `user_karyawan` varchar(50) NOT NULL DEFAULT '0',
11 `nama_karyawan` varchar(50) DEFAULT NULL,
12 `alm_karyawan` varchar(50) DEFAULT NULL,
13 `gaji_karyawan` int(10) DEFAULT NULL,
14 `tgl_gabung` date DEFAULT NULL,
15 PRIMARY KEY (`id_karyawan`)
16) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
17
18-- Dumping data for table tes_db.karyawan: ~10 rows (approximately)
19INSERT IGNORE INTO `karyawan` (`id_karyawan`, `pass_karyawan`, `user_karyawan`, `nama_karyawan`, `alm_karyawan`, `gaji_karyawan`, `tgl_gabung`) VALUES
20 (1, '1234', 'admin', 'Admin Nyekrip', 'Website', 3000000, '2015-04-16'),
21 (2, '4321', 'staf', 'Staf Nyekrip', 'Server Web', 250000, '2015-04-16');
22
23
24
25<------------------------finish databases sistem and flowchart--------------------------------->
26
27<html are---------------------------->
28
291
302
313
324
335
346
357
368
379
3810
3911
4012
4113
4214
4315
4416
4517
4618
4719
4820
4921
5022
5123
5224
5325
5426
5527
5628
5729
5830
5931
6032
6133
6234
6335
6436
65<?php
66include('login.php'); // Memasuk-kan skrip Login
67
68if(isset($_SESSION['login_user'])){
69header("location: profile.php");
70}
71?>
72
73<!DOCTYPE html>
74<html>
75 <head>
76 <title>Nyekrip Form Login</title>
77
78 <!-- Skrip CSS -->
79 <link rel="stylesheet" href="style.css"/>
80
81 </head>
82 <body>
83 <div class="container">
84 <div class="main">
85 <form action="" method="post">
86 <h2>NYEKRIP.COM FORM LOGIN DENGAN PHP</h2><hr/>
87
88 <label>Username :</label>
89 <input id="name" name="username" placeholder="username" type="text">
90
91 <label>Password :</label>
92 <input id="password" name="password" placeholder="**********" type="password">
93
94 <input type="submit" name="submit" id="submit" value="Login">
95 </form>
96 </div>
97 </div>
98
99 </body>
100</html>
101
102<--------------------------php area -------------------->
103<?php
104session_start(); // Memulai Session
105$error=''; // Variabel untuk menyimpan pesan error
106if (isset($_POST['submit'])) {
107 if (empty($_POST['username']) || empty($_POST['password'])) {
108 $error = "Username or Password is invalid";
109 }
110 else
111 {
112 // Variabel username dan password
113 $username=$_POST['username'];
114 $password=$_POST['password'];
115 // Membangun koneksi ke database
116 $connection = mysql_connect("localhost", "root", "");
117 // Mencegah MySQL injection
118 $username = stripslashes($username);
119 $password = stripslashes($password);
120 $username = mysql_real_escape_string($username);
121 $password = mysql_real_escape_string($password);
122 // Seleksi Database
123 $db = mysql_select_db("tes_db", $connection);
124 // SQL query untuk memeriksa apakah karyawan terdapat di database?
125 $query = mysql_query("select * from karyawan where pass_karyawan='$password' AND user_karyawan='$username'", $connection);
126 $rows = mysql_num_rows($query);
127 if ($rows == 1) {
128 $_SESSION['login_user']=$username; // Membuat Sesi/session
129 header("location: profile.php"); // Mengarahkan ke halaman profil
130 } else {
131 $error = "Username atau Password belum terdaftar";
132 }
133 mysql_close($connection); // Menutup koneksi
134 }
135}
136?>
137
138
139<----------------skripsi php + Membuat Halaman Profil---------------------->
140<?php
141include('session.php');
142?>
143<!DOCTYPE html>
144<html>
145 <head>
146 <title>Nyekrip Halaman Khusus</title>
147 <link href="style.css" rel="stylesheet" type="text/css">
148 </head>
149<body>
150 <div id="profile">
151 <b id="welcome">Selamat Datang : <i><?php echo $login_session; ?></i></b>
152 <b id="logout"><a href="logout.php">Log Out</a></b>
153 </div>
154</body>
155</html>
156
157<---------------Membuat Skrip Fungsi Session PHP--------------->
158<?php
159// Membangun Koneksi dengan Server dengan nama server, user_id dan password sebagai parameter
160$connection = mysql_connect("localhost", "root", "");
161// Seleksi Database
162$db = mysql_select_db("tes_db", $connection);
163session_start();// Memulai Session
164// Menyimpan Session
165$user_check=$_SESSION['login_user'];
166// Ambil nama karyawan berdasarkan username karyawan dengan mysql_fetch_assoc
167$ses_sql=mysql_query("select nama_karyawan from karyawan where user_karyawan='$user_check'", $connection);
168$row = mysql_fetch_assoc($ses_sql);
169$login_session =$row['nama_karyawan'];
170if(!isset($login_session)){
171 mysql_close($connection); // Menutup koneksi
172 header('Location: index.php'); // Mengarahkan ke Home Page
173}
174
175
176
177<<<<<<<<<_---------------Membuat Skrip Fungsi Logout PHP----------------->
178
179<?php
180session_start();
181if(session_destroy()) // Menghapus Sessions
182{
183 header("Location: index.php"); // Langsung mengarah ke Home index.php
184}
185?>
186
187
188<--------------------------------cssss area-------------------------->
189.container {
190 width: 50%;
191 margin: 0 auto;
192}
193
194h2{
195 background-color: #53bd84;
196 padding: 30px 35px;
197 margin: -10px -50px;
198 text-align:center;
199 color: #fff;
200}
201
202span{
203 display: block;
204 margin-bottom: 20px;
205 color: red;
206}
207
208.success{
209 display: block;
210 margin-top: 20px;
211 margin-bottom: 0;
212 font-size: 14px;
213}
214
215b{
216 color:green;
217}
218
219hr{
220 margin: 10px -50px;
221 border: 0;
222 border-top: 1px solid #ccc;
223 margin-bottom: 25px;
224}
225
226div.main{
227 width: 306px;
228 padding: 10px 50px 30px;
229 border: 2px solid gray;
230 font-family: raleway;
231 float:left;
232 margin-top:15px;
233}
234
235input[type=text]{
236 width: 96%;
237 height: 25px;
238 padding: 5px;
239 margin-bottom: 25px;
240 margin-top: 5px;
241 border: 2px solid #ccc;
242 color: #53bd84;
243 font-size: 16px;
244}
245
246input[type=password]{
247 width: 96%;
248 height: 25px;
249 padding: 5px;
250 margin-bottom: 25px;
251 margin-top: 5px;
252 border: 2px solid #ccc;
253 color: #53bd84;
254 font-size: 16px;
255}
256
257label{
258 color: #53bd84;
259 text-shadow: 0 1px 0 #fff;
260 font-size: 14px;
261 font-weight: bold;
262}
263
264input[type=submit]{
265 font-size: 16px;
266 background: linear-gradient(#53bd84 5%, #fff 100%);
267 color: #4E4D4B;
268 font-weight: bold;
269 cursor: pointer;
270 width: 100%;
271 padding: 10px 0;
272 outline:none;
273}
274
275#profile {
276 padding:50px;
277 border:1px solid grey;
278 font-size:20px;
279 background-color:#A2DED0;
280}
281#logout {
282 float:right;
283 padding:5px;
284 border:dashed 1px gray
285}
286a {
287 text-decoration:none;
288 color:#6495ed
289}
290i {
291 color:#6495ed
292}