• Terbaru

    Contoh Login Form PHP

    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style/style.css" />
    <title>
    RegiSys
    </title>
    <script type="text/javascript" src="js/js.js"></script>
    </head>
    <div style="margin-top:70px; text-align:center; color:#128680; ">
    <div style="font-size:40px">
    Welcome to <b>U S App</b>
    </div>
    <p>
    <i>Dealer and Service maintenance application</i>
    </p>
    </div>
    <body>
    <div id="loginbox">
    <?
    include "koneksi.php";

    //if the username and password box is empty do :
    if(!empty($_POST['username']) && !empty($_POST['password'])){
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string(md5($_POST['password']));

    //selecting data and checking its existance inside tables
    $checkusercommon=mysql_query("select * from user where username ='".$username."' and password = '".$password."'");
    $checkuseradmin = mysql_query("select * from useradmin where username = '".$username."' and password = '".$password."'");
    $checkusersa = mysql_query("select * from usersa where username = '".$username."' and password = '".$password."'");

    $_SESSION['username']= $username;

    //checking users and then pass them to specific page
    if(mysql_num_rows($checkusercommon) == 0 && mysql_num_rows($checkuseradmin) == 0 && mysql_num_rows($checkusersa) == 0){
    //if the user doesnt exist in all tables dont allow him in
    ?>
    <script>
    alert ("Username not found");
    window.location="index.php";
    </script>
    <?
    }elseif(mysql_num_rows($checkusercommon) != 0 && mysql_num_rows($checkuseradmin) == 0 && mysql_num_rows($checkusersa) == 0){
    //if the user exist inside user table let him in to member page
    ?>
    <script>
    window.location="homepage.php";
    </script>
    <?
    }elseif(mysql_num_rows($checkusercommon) == 0 && mysql_num_rows($checkuseradmin) != 0 && mysql_num_rows($checkusersa) == 0){
    //if the user exist inside admin table let him in to admin page
    ?>
    <script>
    window.location="adminhomepage.php";
    </script>
    <?
    }elseif(mysql_num_rows($checkusercommon) == 0 && mysql_num_rows($checkuseradmin) == 0 && mysql_num_rows($checkusersa) != 0){
    //if the user exist inside usersa table let him in to sa homepage
    ?>
    <script>
    window.location="sahonepage.php";
    </script>
    <?
    }else{
    ?>
    <script>
    alert ("Internal error, please try again");
    window.location="index.php";
    </script>
    <?
    }
    }else{
    ?>
    <form name=myloginfrm action=index.php method=POST onsubmit="checkthisform()">
    <table>
    <tr>
    <th>Username</th><td>:<input  class="inputsmall" type=text name="username" /></td>
    </tr>
    <tr>
    <th>Password</th><td>:<input class="inputsmall" type="password" name="password" /></td>
    </tr>
    <tr>
    <th colspan=2><div style="text-align:right"><input class="loginsubmit" type=submit name=submit id=submit value="Login"/></div></th><td></td>
    </tr>
    </table>
    </form>
    <?
    }
    ?>
    </div>
    </body>
    </html>

    No comments

    Saya sangat berterimakasih apabila sahabat sekalian bersedia untuk tidak meninggalkan spam dan meninggalkan komentar yang berhubungan dengan artikel di atas.