Thursday 31 March 2011

Tugas Praktikum 7 (Pemrosesan Form) - Demo Login Form

Tugas Praktikum 7 (Pemrosesan Form) - Demo Login Form
Eko Fahrudi Silviawan
S1 PTI Input 2010 Gasal
Off F



Download Source Code

Source Code


<?php
session_start();
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>[ Demo Login Form ]</title>
    <link rel="stylesheet" type="text/css" href="TugasPrak7.css" />
</head>

<body>
<script language="javascript" type="text/javascript">
<!--
var inittext = "";

function getValue(){
    var myForm = document.myForm;
    var uName = myForm.uName.value;
    var pass = myForm.uPass.value;

    if (uName == '') {alert ('Username ga boleh kosong!'); myForm.uName.focus(); }
    else if (pass == '') {alert ('Password ga boleh kosong!');  myForm.uPass.focus(); }
    else myForm.submit();
}

function storeinittext(){
    inittext = document.myForm.uName.value;
}

function inputtex_onchange(){
    var inputtex_vlaue = document.myForm.uName.value;
    var filter = /^[a-zA-Z]+$/ ;
    if(!filter.test(inputtex_vlaue))        {
        document.myForm.uName.value = inittext;
    }
}

//-->
</script>
<div class="spFormContainer" style="margin-top:150px; margin-right:auto; margin-left:auto;">
<div class="spFormHeader" style="height:50px; font-size:36px; font-weight:normal; padding-top:25px; color: #45658F;">Login Form</div>
<div id="spForm" style="margin:35px 5px 5px 40px; ">
<?php
$validuName="rudi";
$validUpass="rudi";
$isTryLogin=0;
if(isset($_POST['uName'])){
    if(($uName==$validuName) and ($uPass==$validUpass)){
        echo "Berhasil Login! (^_^)<br>
              <br>
              Selamat Datang<br>
              Username: rudi<br>
              Password: rudi";
        $_SESSION['uState']=1;
        $isTryLogin=1;
        echo '<form id="logoutForm" name="logoutForm" action="'.$_SERVER['PHP_SELF'].'" method="post"><input type="submit" name="btLogout" id="btLogout" onclick="logout();" value="Logout" style="float:right;margin-right:40px;font-weight:bold;color:#283C55;width:55px;height:30px;" /></form>';
    }else{
        echo '<span style="color:red;">Username atau Password yang Anda masukkan salah! (T,T)</span><br>';
        $_SESSION['uState']=0;
    }
}
if(isset($btLogout)){
    $_SESSION['uState']=0;
}
if($_SESSION['uState']==0){?>
    <form id="myForm" name="myForm" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <div class="spFormChild">
        <label for="uName">Username</label>
        <input type="text" name="uName" id="uName" onfocus="storeinittext();" onchange="inputtex_onchange();" />
    </div>
    <div class="spFormChild" style="margin-top:15px;">
        <label for="uPass">Password</label>
        <input type="password" name="uPass" id="uPass" />
    </div>
    <div class="spFormChild" style="margin-top:7px;">
        <input type="button" name="btOk" id="btOk" onclick="getValue();" value="Login" style="float:right;margin-right:40px;font-weight:bold;color:#283C55;width:55px;height:30px;" />
    </div>
    </form>
    <script type="text/javascript">
        document.myForm.uName.focus();
    </script>
    <?php
}elseif($isTryLogin==0){
    echo "Berhasil Login! (^_^)<br>
          <br>
          Selamat Datang<br>
          Username: rudi<br>
          Password: rudi";
    echo '<form id="logoutForm" name="logoutForm" action="'.$_SERVER['PHP_SELF'].'" method="post"><input type="submit" name="btLogout" id="btLogout" onclick="logout();" value="Logout" style="float:right;margin-right:40px;font-weight:bold;color:#283C55;width:55px;height:30px;" /></form>';
}
?>
</div>
</div>
<div style="padding:2px 0 2px 7px;border:2px solid #84A0C4;border-top:0px;width:293px;background-color:#ECF2FB;margin-right:auto;margin-left:auto;">
Username yang benar : rudi<br />
Password yang benar : rudi<br /><br />
Eko Fahrudi Silviawan - 100533406929<br />
S1 PTI Input 2010 Gasal Off F
</div>
</body>
</html>

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More