Share |

Form Login

11:48 / Diposting oleh adien /

Hampir semua web dinamis memiliki halaman login baik itu untuk identitas anggota ataupun untuk mendapatkan fasilitas lebih dari web yang diikuti. Nah sekarang kita mencoba untuk membuat sebuah script login sederhana. Bagi para php programmer mungkin listing terlalu sederhana, tapi kita selalu memulai dari yang sederhana terlebih dahulu.

Berikut merupakan script login sederhana:


<!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>Tugas login</title>

</head>
<body>

<?php
/*=============================================================
php simple page login ver. 0.2
---------------------------------------------------------------
(c) 2010 Akhmad Rosyidin
Website: http://ro-luck.co.cc
License: Freely copy & use, but include this notice.
--------------------------------------------------------------
This script is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability of fitness for a particular purpose.
--------------------------------------------------------------
question, bugs, support, idea or money :)?
contact me from email or website contact form.
===============================================================*/


$adminpass = "5f4dcc3b5aa765d61d8327deb882cf99"; //password is "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 {
// this page secret if you correct enter password.
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>

Label:

0 komentar:

Posting Komentar