PHP開發用戶登入模組之HTML登入頁面

先用HTML+CSS程式碼寫出一個簡單樣式的提交表單

<!DOCTYPE html>
<html>
<head>
    <title>用户登录页面</title>
    <meta charset="UTF-8"/>
    <style type="text/css">
        *{margin:0px;padding:0px;}
        ul{
            width:400px;
            list-style:none;
            margin:50px auto;
        }
        li{
            padding:12px;
            position:relative;
        }
        label{
            width:80px;
            display:inline-block;
            float:left;
            line-height:30px;
        }
        input[type='text'],input[type='password']{
            height:30px;
        }
        img{
            margin-left:10px;
        }
        input[type="submit"]{
            margin-left:80px;
            padding:5px 10px;
        }
    </style>
</head>
<body>
<form action="logins.php" method="post">
    <ul>
        <li>
            <label>用户名:</label>
            <input type="text" name="username" placeholder="请输入登录账号"/>
        </li>
        <li>
            <label>密码:</label>
            <input type="password" name="password" placeholder="请输入密码" />
        </li>
        <li>
            <label>验证码:</label>
            <input type="text" name="code" size="4" style="float:left"/>
        </li>
        <li>
            <input type="submit" value="登录" />
        </li>
    </ul>
</form>
</body>

其次,為了在裡面顯示驗證碼模組,需要加入JavaScript語句,引入一個外部驗證碼的PHP檔案:

<body>
<li>
    <label>验证码:</label>
    <input type="text" name="code" size="4" style="float:left"/>
    <a href="javascript:;" onclick="document.getElementById('captcha_img').src='captcha.php?r='+Math.random()">
        <img id="captcha_img" border='1' src='captcha.php?r=echo rand(); ?>' style="width:100px; height:30px" />
    </a>
</li>
</body>

註解:

captcha.php就是外部驗證碼文件,可以透過JavaScript的onclick事件來變更驗證碼。

以下是完整的登入頁面login.html檔案程式碼:

<!DOCTYPE html>
<html>
<head>
    <title>用户登录页面</title>
    <meta charset="UTF-8"/>
    <style type="text/css">
        *{margin:0px;padding:0px;}
        ul{
            width:400px;
            list-style:none;
            margin:50px auto;
        }
        li{
            padding:12px;
            position:relative;
        }
        label{
            width:80px;
            display:inline-block;
            float:left;
            line-height:30px;
        }
        input[type='text'],input[type='password']{
            height:30px;
        }
        img{
            margin-left:10px;
        }
        input[type="submit"]{
            margin-left:80px;
            padding:5px 10px;
        }
    </style>
</head>
<body>
<form action="logins.php" method="post">
    <ul>
        <li>
            <label>用户名:</label>
            <input type="text" name="username" placeholder="请输入登录账号"/>
        </li>
        <li>
            <label>密码:</label>
            <input type="password" name="password" placeholder="请输入密码" />
        </li>
        <li>
            <label>验证码:</label>
            <input type="text" name="code" size="4" style="float:left"/>
            <a href="javascript:;" onclick="document.getElementById('captcha_img').src='captcha.php?r='+Math.random()">
                <img id="captcha_img" border='1' src='captcha.php?r=echo rand(); ?>' style="width:100px; height:30px" />
            </a>
        </li>
        <li>
            <input type="submit" value="登录" />
        </li>
    </ul>
</form>
</body>
</html>

顯示效果:

dd.png

繼續學習
||
<!DOCTYPE html> <html> <head> <title>用户登录页面</title> <meta charset="UTF-8"/> <style type="text/css"> *{margin:0px;padding:0px;} ul{ width:400px; list-style:none; margin:50px auto; } li{ padding:12px; position:relative; } label{ width:80px; display:inline-block; float:left; line-height:30px; } input[type='text'],input[type='password']{ height:30px; } img{ margin-left:10px; } input[type="submit"]{ margin-left:80px; padding:5px 10px; } </style> </head> <body> <form action="logins.php" method="post"> <ul> <li> <label>用户名:</label> <input type="text" name="username" placeholder="请输入登录账号"/> </li> <li> <label>密码:</label> <input type="password" name="password" placeholder="请输入密码" /> </li> <li> <label>验证码:</label> <input type="text" name="code" size="4" style="float:left"/> <a href="javascript:;" onclick="document.getElementById('captcha_img').src='captcha.php?r='+Math.random()"> <img id="captcha_img" border='1' src='captcha.php?r=echo rand(); ?>' style="width:100px; height:30px" /> </a> </li> <li> <input type="submit" value="登录" /> </li> </ul> </form> </body> </html>