Leakbali
w3 Tutorial, Web Tutorial
Switch to English Bahasa Indonesia 
Register   Login

Source Code  


Share

PHP Simple Login Form 

Here is PHP simple login form. In the code below we can see how the script work to make user can login into authenticate page.
<?php 
session_start();
mysql_connect("localhost", "root", ""); //buat koneksi database
mysql_select_db("myweb"); //pilih database
$mode = $_GET['mode'];
$id = $_GET['id'];
if($mode == "del"){
	//menghapus data
	mysql_query("DELETE FROM bukutamu WHERE id = '".$id."'");
	echo "<script>location.href='index.php';</script>";
}
if($mode == "app"){
	//approve data
	mysql_query("UPDATE bukutamu SET status = 1 WHERE id = '".$id."'");
	echo "<script>location.href='index.php';</script>";
}
?>
<html>
<head>
<title>MyWebsite</title>
<link rel="stylesheet" type="text/css" href="css.css" />
</head>
<body>
<a name="atas" href="index.php#bawah">Kebawah</a>
<div id="kontainer">
	<div id="header">
		<div id="menu">
			<?php include "menu.php";?>
		</div>
	</div>
	<div style="margin : 20px; auto;">
	
	<?php
$username = $_POST['username']; //admin
$password = $_POST['password']; //admin
$submit = $_POST['submit'];
if(isset($submit)){
	if(empty($username) || empty($password)){
		echo "<script>alert('Empty Username or Password!');</script>";
		$msg = 1;
	}
	if($msg != 1){ //inisialisasi parameter login
		$pass = MD5($password); //enkripsi password dengan hash MD5
		$_a = mysql_query("SELECT user, pass FROM login WHERE user = '".$username."' AND pass = '".$pass."'");
		$a = mysql_fetch_array($_a);
		$t = mysql_num_rows($_a);
		if($t == 0){ 
			echo "Username atau password salah!";
		}else{ 
			//membuat definisi parameter login
			session_register($username);
			$_SESSION['username'] = $username;
		}
	}
}
?>
<?php if($_SESSION['username'] == ""){?>
<p align="center">
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
Username : <input type="text" name="username" /><br />
Password : <input type="password" name="password" /><br />
<input type="submit" name="submit" value=" LOGIN " />
</form>
<?php }else{?>
<a href='logout.php'>Logout</a><br />
<h1>SELAMAT DATANG <?php echo $_SESSION['username'];?></h1>
<p>Kelola Bukutamu</p>
<?php
$_bt = mysql_query("SELECT id, nama, email, komentar, tanggal, status from bukutamu ORDER by nama ASC");
while ($bt = mysql_fetch_array($_bt)){
?>
<?php echo $bt['nama'];?>, <?php echo $bt['email'];?> Status (<?php echo $bt['status'];?>) [<a onclick="return confirm('Delete bukutamu?');" href="index.php?mode=del&id=<?php echo $bt['id'];?>">Delete</a>][<a onclick="return confirm('Approve bukutamu?');" href="index.php?mode=app&id=<?php echo $bt['id'];?>">Approve</a>]<br />
<?php echo $bt['komentar'];?><br /><br />
<?php }?>
<?php }?>
	</div>
</div>
</body>
</html>
You can download the complete files below:
Download
Post by : Oka Dayendra
Post on : 01 July 2011
File : simple_login.zip, size : 0 bytes
Title : PHP Simple Login Form
Category : PHP
Source : http://www.leakbali.com
Comment (0)
Name *
Email *
Website
example : http://www.google.com or http://www.yourname.com
Comment *
Security Code *

Related Articles

Source Code


References

About Us

Home
About Us
Contact Us
Sitemap

Tools

Google PageRank
Alexa Rank
Keywords Density

Accounts

Register Account
Login
Valid XHTML 1.0 TransitionalValid CSS!
Web Directory


2006 - 2012 © Leakbali.com - Free Web Tutorial, Free Web Articles, Web Sharing, Source Codes, Web References