PHP開(kāi)發(fā)登入頁(yè)面之PHP頁(yè)面
登入頁(yè)面之PHP頁(yè)面
我們?cè)贖TML表單輸入的使用者名稱(chēng)和密碼,以及驗(yàn)證碼需要我們進(jìn)行判斷,判斷是否和資料庫(kù)裡的資料一樣,如果不一樣是要給出相關(guān)的提示的,以及驗(yàn)證通過(guò),所返回的頁(yè)面...這些功能在我們的PHP頁(yè)面完成,
程式碼如下
<?php session_start(); header("Content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','root','root','login'); //鏈接數(shù)據(jù)庫(kù) mysqli_set_charset($link ,'utf8'); //設(shè)定字符集 $name=$_POST['username']; $pwd=$_POST['password']; $yzm=$_POST['yzm']; if($name==''){ echo "<script>alert('請(qǐng)輸入用戶名');location='" . $_SERVER['HTTP_REFERER'] . "'</script>"; exit; } if($pwd==''){ echo "<script>alert('請(qǐng)輸入密碼');location='" . $_SERVER['HTTP_REFERER'] . "'</script>"; exit; } if($yzm!=$_SESSION['VCODE']){ echo"<script>alert('你的驗(yàn)證碼不正確,請(qǐng)重新輸入');location='".$_SERVER['HTTP_REFERER']. "'</script>"; exit; } $sql_select="select id,username,password from user where username= ?"; //從數(shù)據(jù)庫(kù)查詢(xún)信息 $stmt=mysqli_prepare($link,$sql_select); mysqli_stmt_bind_param($stmt,'s',$name); mysqli_stmt_execute($stmt); $result=mysqli_stmt_get_result($stmt); $row=mysqli_fetch_assoc($result); if($row){ if($pwd !=$row['password'] || $name !=$row['username']){ echo "<script>alert('密碼錯(cuò)誤,請(qǐng)重新輸入');location.href='login.html'</script>"; exit; } else{ $_SESSION['username']=$row['username']; $_SESSION['id']=$row['id']; echo "<script>alert('登錄成功');location.href='first.html'</script>"; } }else{ echo "<script>alert('您輸入的用戶名不存在');location.href='login.html'</script>"; exit; };
上面的是程式碼我們對(duì)密碼,用戶名,驗(yàn)證碼進(jìn)行了判斷,及給出了相關(guān)提示訊息。
但是當(dāng)我們沒(méi)有帳號(hào)登入時(shí),我們就需要註冊(cè)個(gè)帳號(hào),這樣才能登入。下面的章節(jié),就為大家示範(fàn)怎麼做註冊(cè)頁(yè)面