PHP開發登入頁面之HTML頁面

我們先看下圖

login.jpg


從上面的圖可以看到,我們的登入頁面運用了三個<input>標籤輸入網域,一個註冊連結<a>,一個立即登入按鈕<button>外加一個驗證碼,就構成了我們的登入頁面,但是如果需要我們的頁面更好看,css樣式是必不可少的,本章節的css樣式如下所示

<style type="text/css">
       body{background-image: url("/images/1.jpg")}
       .container{
           width: 380px;
           height: 330px;
           margin: 0 auto;margin-top: 240px;
           box-shadow: 0 0 20px #222;
           border-radius:40px;
          background-color: rgba(152, 242, 242, 0.23);
       }
    div.right{
        position: relative;
        left: 40px;
        top: 20px;
    }
     input{
         width: 180px;
         height: 25px;
     }
    .button{
        background-color: rgba(230, 228, 236, 0.93); /* Green */
        border: none;
        color: #110c0f;
        padding: 10px 30px;
        text-align: center;
        display: inline-block;
        font-size: 16px;
        margin-top: -40px;
        margin-left: 50px;
        cursor: pointer;
    }
</style>

驗證碼

#本章節所運用的驗證碼程式碼如下所示

<?php
session_start();
Header("Content-type:image/PNG");
$im = imagecreate(60, 25);
$back = imagecolorallocate($im, 245, 245, 245);
imagefill($im, 0, 0, $back);
$vcodes = "";

for($i = 0; $i < 4; $i++){
    $font = imagecolorallocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
    $authnum = rand(0, 9);
    $vcodes .= $authnum;
    imagestring($im, 5, 9 + $i * 10, 5, $authnum, $font);
}
$_SESSION['VCODE'] = $vcodes;
for($i=0;$i<200;$i++) {
    $randcolor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
    imagesetpixel($im, rand()%60, rand()%25, $randcolor); //
}
imagepng($im);
imagedestroy($im);
?>

我們需要在我們登入之前在我們的HTML頁面做一個判斷,如果我們的用戶名,密碼,驗證碼不輸入就登錄的話,我們要提示用戶用戶輸入相關的資訊才能登錄,這樣我們就可以用我們的JS(JavaScript)判斷了,

#JS程式碼如下##

<script type="text/javascript">
function foo(){
        if(myform.name.value=="")
        {
            alert("请输入用户名");
            myform.name.focus();
            return false;
        }
        if (myform.pwd.value=="")
        {
            alert("请输入密码");
            myform.pwd.focus();
            return false;
        }
        if (myform.yzm.value=="")
        {
            alert("请输入验证码");
            myform.yzm.focus();
            return false;
        }
    }
</script>


完整的HTML頁面程式碼

#login.html 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆界面</title>

    <script type="text/javascript">
    function foo(){

            if(myform.name.value=="")
            {
                alert("请输入用户名");
                myform.name.focus();
                return false;
            }
            if (myform.pwd.value=="")
            {
                alert("请输入密码");
                myform.pwd.focus();
                return false;
            }
            if (myform.yzm.value=="")
            {
                alert("请输入验证码");
                myform.yzm.focus();
                return false;
            }
        }
    </script>

    <style type="text/css">
           body{background-image: url("/images/1.jpg")}
           .container{
               width: 380px;
               height: 330px;
               margin: 0 auto;margin-top: 240px;
               box-shadow: 0 0 20px #222;
               border-radius:40px;
              background-color: rgba(152, 242, 242, 0.23);
           }

        div.right{
            position: relative;
            left: 40px;
            top: 20px;
        }
         input{
             width: 180px;
             height: 25px;

         }

        .button{
            background-color: rgba(230, 228, 236, 0.93); /* Green */
 border: none;
            color: #110c0f;
            padding: 10px 30px;
            text-align: center;
            display: inline-block;
            font-size: 16px;
            margin-top: -40px;
            margin-left: 50px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<form action="login.php" method="post" onsubmit="return foo();" name="myform" >

 <div class="container"style="font-size:17px">
     <div class="right">
    <h2>用户登陆</h2>

     <p>
         用户名:<input type="text" name="name" id="name" placeholder="请输入用户名">
     </p>

     <p>
         密&#12288码:<input type="password" id="pwd" placeholder="请输入密码" >
     </p>

     <p>
         验证码:<input type="text" name="yzm" id="yzm" id="yzm" placeholder="请输入验证码">
         <img src="yanzhengma.php" onClick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand">

     </p>
         <p style=" margin-left: 200px"><a href="zhuce.html">注册</a></p>

       <p>
             <button class="button">立即登陆</button>
       </p>


   </div>
 </div>

</form>
</body>
</html>

運行程式嘗試一下


這樣我們的HTML頁面就做出來了,下一步就要提交到我們的login.php 頁面進行下一步處理了



繼續學習
||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登陆界面</title> <script type="text/javascript"> function foo(){ if(myform.name.value=="") { alert("请输入用户名"); myform.name.focus(); return false; } if (myform.pwd.value=="") { alert("请输入密码"); myform.pwd.focus(); return false; } if (myform.yzm.value=="") { alert("请输入验证码"); myform.yzm.focus(); return false; } } </script> <style type="text/css"> body{background-image: url("https://img.php.cn/upload/course/000/000/006/5811779a6dae7451.jpg")} .container{ width: 380px; height: 330px; margin: 0 auto;margin-top: 240px; box-shadow: 0 0 20px #222; border-radius:40px; background-color: rgba(152, 242, 242, 0.23); } div.right{ position: relative; left: 40px; top: 20px; } input{ width: 180px; height: 25px; } .button{ background-color: rgba(230, 228, 236, 0.93); /* Green */ border: none; color: #110c0f; padding: 10px 30px; text-align: center; display: inline-block; font-size: 16px; margin-top: -40px; margin-left: 50px; cursor: pointer; } </style> </head> <body> <form action="" method="post" onsubmit="return foo();" name="myform" > <div class="container"style="font-size:17px"> <div class="right"> <h2>用户登陆</h2> <p> 用户名:<input type="text" name="name" id="name" placeholder="请输入用户名"> </p> <p> 密&#12288码:<input type="password" name="pwd" id="pwd" placeholder="请输入密码" > </p> <p> 验证码:<input type="text" name="yzm" id="yzm" placeholder="请输入验证码"> <img src="yanzhengma.php" onClick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand"> </p> <p style=" margin-left: 200px"><a href="zhuce.html">注册</a></p> <p> <button class="button">立即登陆</button> </p> </div> </div> </form> </body> </html>