html网页登录时用户信息如何验证

html-css021

html网页登录时用户信息如何验证,第1张

我觉得php是最好用的

php版本7.x 开启pdo,嘛~我自己用的,自己理解后修改吧~

登陆:[login.php]

<!DOCTYPE html>

<html>

<head>

<title>demo</title>

<meta charset="UTF-8">

<style>

a{

width:100px

}

</style>

</head>

    <body>

    </div>

        <form action="" method="post">

            <input type="username" placeholder="Account" name="username" id="usr" required autocomplete="off"><br>

            <input type="password" placeholder="Password" name="password" id="psd" required autocomplete="off"><br>

            <button name="submit" type="submit" id="butn">Login!</button>

        </form>

    </div>

<style>

body{

background-repeat:no-repeat

}

.head{

background-color:rgba(254,224,223,0.5)

width:100%

}

.getAcc{

border:none

margin:100px auto

box-shadow:4px 4px rgba(255,255,255,0.3)

width:500px

height:300px

background:white

}

.getAcc input{

background:none

padding-bottom:0

border-width:0 0 2px

border-color:rgba(254,224,223,1)

outline:none

}

.getAcc .usr{

position:absolute

left:50%

top:230px

}

.getAcc .psd{

position:absolute

left:50%

top:280px

}

.getAcc button{

position:absolute

left:55%

top:310px

width:100px

height:33px

background:none

border:none

outline:none

margin: auto 5px auto auto

color:rgb(232,122,144)

}

.getAcc button:focus{

background:rgba(244,167,185,0.5)

transition:all 0.5s ease

}

.getAcc input:focus{

border-color:rgb(232,122,144)

transition:all 0.5s ease-in-out

}

div#aira img{

position:absolute

top:210px

left:40%

width:155px

height:220px

margin:auto 5px auto auto

}

.getAcc input{

vertical-align:middle

}

.getAcc form{

margin:10px 10px

}

input:-webkit-autofill{

background-color:none

}

.head a:hover{

width:220px

}

ul a{

width:220px

}

</style>

</body>

<?php

if(isset($_POST["submit"]))//只用submit存在才能执行

    {

        $dbh = new PDO("mysql:host=数据库地址dbname=数据库名字","用户名","管理密码")

        $usr=$_POST["username"]

        $pwd=$_POST["password"]

        $cusr=$dbh->query("select username from users where username='$usr'")

        $cpwd=$dbh->query("select username from users where username='$usr' and password='$pwd'")

        //执行查询语句

        $row1=$cusr->fetch(PDO::FETCH_BOTH)

        //$row1为cusr执行后将返回结果转换成行数组格式

        $row2=$cpwd->fetch(PDO::FETCH_BOTH)

        if(empty($row1[0]))//若为空则表示没有匹配到任何条目

        {

            $dbh=null//断开数据库

        ?>

<script>

            alert ("账号不存在")

</script>

<?php       

        }

        else if(empty($row2[0]))//同上

        {

            $dbh=null

?>

<script>

            alert ("密码/账号错误!")

 </script>

<?php

        }

        else

        {

            $dbh=null

?>

<?php

        }

    }

?>

注册[register.php]

<!DOCTYPE html>

<html>

<head>

<title>demo</title>

<meta charset="utf-8">

</head>

<body>

<div id="r_fm">

<form action="" method="post">

<input type="username" id="reg_urn" required name="username" autocomplete="off" placeholder="Username">

<input type="password" id="reg_pwd" required name="password" autocomplete="off" placeholder="Password">

<button name="submit" value="submit">Register</button>

</form>

</div>

</body>

</html>

<?php

if(isset($_POST["submit"]))

{

header("charset='utf-8'")

$dbh = new PDO("mysql:host=数据库地址dbname=数据库名字","用户名","管理密码")

$urn=$_POST["username"]

$check_length = strlen($_POST["password"])

if($check_length<6||$check_length>16)

{

echo '

<script>

alert("The length of the password should between 6 and 26!")

</script>

'

}

else

{

$pwd=$_POST["password"]

$sql = "insert into users values ('$urn','$pwd')"

$ck_true = $dbh->query('select username from users where username="$urn"')

$row_ck1=$ck_true->fetch(PDO::FETCH_BOTH)

if(empty($row_ck1[0]))

{

$dbh->exec($sql)

$dbh=null

echo '

<script>

window.location.href="/login.php"

</script>'

}

else

{

$dbh=null

echo "<script> alert('ERROR') </script>"

}

}

}

?>

<script type="text/javascript" language="javascript">

function toUrl(){

var isLogin =用户是否登录(boolean 登录为真,未登录为假)

if(isLogin){

window.location="Login.html"//登录用户去此链接

}else{

window.location="noLogin.html"//未登录用户去此链接

}

}

<script>

<body>

<a href="#" onclick="toUrl()">go to the page</a>

</body>

<html><head> <title>登陆页面</title></head> <form action="login_conf.jsp" method="post"> 用户登陆 用户名:<input type="text" name="uname">密码: <input type="password" name="upassword"> <input type="submit" value="提交"> <input type="reset" value="重置"> </form></body></html>****************************************************验证页面jsp代码如下:<html> <head> <title>用户验证页面</title> </head> <h1>登陆范例-登陆成功</h1></html>不知道你用啥样的前台 是jsp还是asp.net或者是php