Sabtu, September 23Perahu Layar Kertas

Membuat Login PHP dan MYSQL

setelah kemarin buat login dengan oracle, kini akan saya berikan sedikit tutorial login :

buat file index.php

<html>
<head></head>
<body>
<a href=”login.php”>Login Sekarang</a>
</body>
</html>


setelah itu buat file login.php

<?php
/*======================================================
Scripting oleh : Andhika Nur Afian
Website : http://fieyanh.blogspot.com
Build Code : PHP, JQuery, CSS3, HTML5, JS
Email : andhika.na@gmail.com
========================================================*/
$user=$_SESSION[‘user’];
$pass=$_SESSION[‘sandi’];
if(($user==””)||($pass==””)){
?>
<form action=”log.php?page=in” method=”post”>
<fieldset>
<h3>Sudah terdaftar?</h3>
<h4>Masukkan informasi login Anda.</h4>
<p class=”text” style=”margin-top:-5px”>
<label for=”username”>Username:</label>
<span><input type=”text” id=”username” name=”username” class=”account_input”></span>
</p>
<p class=”text”>
<label for=”password”>Kata sandi:</label>
<span><input type=”password” id=”password” name=”password” class=”account_input”></span>
</p>
<p class=”submit”>
<input type=”button” id=”ResetLogin” name=”ResetLogin” class=”button float_l” onclick=”document.location.href=’?page=login'” value=”Reset” >
<input type=”submit” id=”SubmitLogin” name=”SubmitLogin” class=”button float_r” value=”Masuk” >
</p>
<!–<p class=”lost_password”><a href=”#”>Lupa kata sandi?</a></p>–>
</fieldset>
</form>
<?php
}else
echo”<script>window.location.href=’index.php’;</script>”;
?>

ini file log.php

<?php
session_start();
include “koneksi.php”;
$user=$_SESSION[‘username’];
$pelanggan_id=$_SESSION[‘pelanggan_id’];
$username = $_POST[‘username’];
$password=md5($_POST[‘password’]);
$op = $_GET[‘page’];
if($op==”in”){
$cek = mysql_query(“SELECT * FROM pelanggan WHERE pelanggan_username=’$username’ AND pelanggan_password=’$password'”);
if(mysql_num_rows($cek)==1){
$c = mysql_fetch_array($cek);
$_SESSION[‘username’] = $c[‘pelanggan_username’];
$_SESSION[‘password’] = $c[‘pelanggan_password’];
$_SESSION[‘pelanggan_id’] = $c[‘pelanggan_id’];
mysql_query(“UPDATE pelanggan SET pelanggan_log = ‘1’ WHERE pelanggan_id = ‘$pelanggan_id'”);
echo”<script>window.location=’index.php?’;</script>”;
}
else{
//print “<script>alert(‘Maaf, Password atau Username tidak Valid, Silahkan coba lagi!!!’);javascript:history.go(-1);</script>”;
echo “<script>alert(‘Maaf, Password atau Username tidak Valid, Silahkan coba lagi!!!’); window.back();</script>”;exit;
}
}
else if($op==”out”){
include(‘order_tmp_batal.php’);
//unset($_SESSION);
unset($_SESSION[‘username’]);
unset($_SESSION[‘password’]);
unset($_SESSION[‘pelanggan_id’]);
//session_destroy();
mysql_query(“UPDATE pelanggan SET pelanggan_log = ‘0’ WHERE pelanggan_id = ‘$pelanggan_id'”);
echo “<script>window.location=’index.php’;</script>”;
}

?>


silahkan anda utak atik sendiri ya kawan…

Baca Lainnya :   Karnaval Taman Kanak-Kanak (TK) Se-Kec Bancar | 11 Agustus 2016 | HUT RI Ke-71

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *