Dengan PHP kita juga bisa membuat aplikasi form login sederhana (tanpa database). form login ini terdiri dari field ID/username dan password. spesifikasinya antara lain:
1. field tidak boleh kosong (harus di isi)
2.jika password dan id sesuai akan muncul pesan selamat datang dan mencetak nilai id
3. id/username yang dipake: Dania, password: teram59
berikut adalah sintaknya:
<!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 Form</title>
<script language="javascript" type="text/javascript">
function cek(){
var user= document.getElementById('userid').value;
var pass= document.getElementById('passwd').value;
if(user.replace(/^\s+|\s+$/g, '')==''){
alert('Username Harus Diisi!');
return false;
}
if(pass.replace(/^\s+|\s+$/g, '')==''){
alert('Password Harus diisi!');
return false;
}
return true;
}
</script>
</head>
<body bgcolor="aqua">
<form name="login" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p align="center"><? echo $status;?></p>
<table width="500" border="6" align="center" bgcolor="green" rules="groups" cellpadding="8" cellspacing="5">
<tr>
<td width="50"> </td>
<td align="left"><font size="10" face="Comic Sans ms" color="#06F9E0">Login</font></td>
</tr>
<tbody >
<tr><td width="50"> </td><td><font size="4" face="verdana">Username</font></td></tr>
<tr><td width="50"> </td><td><input type="text" name="userid" size="50" id="userid" /></td></tr>
<tr><td width="50"> </td><td><font size="4" face="verdana">Password</font></td></tr>
<tr><td width="50"> </td><td><input type="password" name="passwd" size="50" id="passwd" /></td></tr>
<tr><td width="50"> </td><td><input name="submit" type="submit" onClick="return cek()" value="LOGIN" /></td></tr>
</table>
</form>
<?php
if (is_string($_POST['userid'])){
if ($_POST['userid']=='Dania'){echo 'Selamat Datang ' .$_POST['userid']; }
else{echo 'Username Anda Salah!!!';}
}
if (is_string($_POST['userid'])){
if ($_POST['passwd']=='teram59'){echo '<br/>Password Anda ' .$_POST['passwd']; }
else{echo '<br/>Password Anda Salah!!!';}
}
?>
</body>
</html>
Dan hasilnya adalah:
oke deh, selamat mencoba...
1. field tidak boleh kosong (harus di isi)
2.jika password dan id sesuai akan muncul pesan selamat datang dan mencetak nilai id
3. id/username yang dipake: Dania, password: teram59
berikut adalah sintaknya:
<!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 Form</title>
<script language="javascript" type="text/javascript">
function cek(){
var user= document.getElementById('userid').value;
var pass= document.getElementById('passwd').value;
if(user.replace(/^\s+|\s+$/g, '')==''){
alert('Username Harus Diisi!');
return false;
}
if(pass.replace(/^\s+|\s+$/g, '')==''){
alert('Password Harus diisi!');
return false;
}
return true;
}
</script>
</head>
<body bgcolor="aqua">
<form name="login" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p align="center"><? echo $status;?></p>
<table width="500" border="6" align="center" bgcolor="green" rules="groups" cellpadding="8" cellspacing="5">
<tr>
<td width="50"> </td>
<td align="left"><font size="10" face="Comic Sans ms" color="#06F9E0">Login</font></td>
</tr>
<tbody >
<tr><td width="50"> </td><td><font size="4" face="verdana">Username</font></td></tr>
<tr><td width="50"> </td><td><input type="text" name="userid" size="50" id="userid" /></td></tr>
<tr><td width="50"> </td><td><font size="4" face="verdana">Password</font></td></tr>
<tr><td width="50"> </td><td><input type="password" name="passwd" size="50" id="passwd" /></td></tr>
<tr><td width="50"> </td><td><input name="submit" type="submit" onClick="return cek()" value="LOGIN" /></td></tr>
</table>
</form>
<?php
if (is_string($_POST['userid'])){
if ($_POST['userid']=='Dania'){echo 'Selamat Datang ' .$_POST['userid']; }
else{echo 'Username Anda Salah!!!';}
}
if (is_string($_POST['userid'])){
if ($_POST['passwd']=='teram59'){echo '<br/>Password Anda ' .$_POST['passwd']; }
else{echo '<br/>Password Anda Salah!!!';}
}
?>
</body>
</html>
Dan hasilnya adalah:
oke deh, selamat mencoba...