Welcome

widget

29 Maret 2010

Pembuatan Form Login dengan PHP

Untuk membuat form Login secara sederhana dalam bahasa php dapat ditujukan pada kode program berikut ini:
1. ketik program berikut ke dalam notepad
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"

lang="en">

<head>
<title>Login</title>

</head>
<body>

<?php


$adminpass = "5f4dcc3b5aa765d61d8327deb882cf99";

"password" (md5 encryption).

session_start();

function admin(){
if(isset($_GET['logout'])) {
unset($_SESSION['logpassneh']);
echo"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$_SERVER

[PHP_SELF]\">"; }

else {
echo"<h1>Login Successful....<br />This is Page Secret<br

/>Thanks for Login</h1>
<a href=\"$_SERVER[PHP_SELF]?logout=1\">Logout</a>";
// end of page secret
} }

if(isset($_POST['password'])) {
$_POST['password']=md5($_POST['password']);
if($_POST['password']==$adminpass) {
$_SESSION['logpassneh'] = $_POST['password'];
admin(); }
else {
$true = explode("'", "Selamat Datang. ' Try Again!");
echo"<h1><font color=green>$true[0]</font></h1><a

href=\"$_SERVER[PHP_SELF]\">$true[1]</a>"; } }



elseif(isset($_SESSION['logpassneh'])) {
if($_SESSION['logpassneh']==$adminpass) {
admin(); } }

else {
echo"
<form method=POST>
Username<br />
<input type=username size=20 name=username> <br /><br />

Password<br />
<input type=password size=20 name=password> <br /><br />

<input type=submit name=login value=\"LOGIN \">
</form>"; }
?>

</body>

</html>

2. simpan dalam ekstensi .php
3. maka hasilnya seperti berikut:

4. selamat mencoba