本文目錄一覽:
PHP模擬用戶登錄模塊
html(login.html)
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ /
title用戶登錄頁面/title
script language=”javascript”
function check(){
var user = document.getElementById(“user”);
var passwd = document.getElementById(“passwd”);
if(user.value.length == 0){
alert(“用戶名不能為空!”);
return false;
}
if(passwd.value.length 6){
alert(“密碼至少6位!”);
return false;
}
}
/script
/head
body
div style=” width:300px; height:200px; margin:auto auto;”
form name=”login” method=”post” action=”check_login.php”
table width=”300″ height=”200″ cellpadding=”0″ cellspacing=”0″ border=”1px”
tr
td height=”70″用戶名:/td
tdinput id=”user” name=”username” type=”text” //td
/tr
tr
td height=”78″密碼/td
tdinput id=”passwd” name=”password” type=”password” //td
/tr
tr
td colspan=”2″centerinput type=”submit” value=”登錄” onclick=”return check();” /input type=”reset” value=”重置” //center/td
/tr
/table
/form
/div
/body
/html
php(check_login.php)
?php
/*
* 驗證登錄頁
* 2015-6-6
* 預設用戶名admin,密碼1234567,
* 如果相同則顯示登錄成功!,錯誤則顯示用戶或密碼錯誤;
*/
$username = $_POST[‘username’];
$password = $_POST[‘password’];
if($username == ‘admin’ $password ==’1234567′){
echo “登錄成功!”;
}else{
echo “用戶或密碼錯誤”;
}
?
PHP 登陸模塊,要求只能使用郵箱註冊,另外上傳的內容默認為未審核,需管理員審核後才能顯示,
填寫郵箱的時候可以用正則判斷一下就行,網上現成的例子不少。 上傳的數據默認為未審核,你可以在資料庫定義一個欄位為status,默認值為0(就是不需要手動添加,資料庫的默認列值),審核之後改為1。在頁面輸出的時候只輸出status=1的
關於php的登錄模塊的問題
在default.php里把「密碼錯誤這些信息」存到$_SESSION里,如:$_SESSION[‘err_msg’] = 「密碼錯誤這些信息」;之後就轉回到login.php中,用header(“Location: 你的工程名/login.php”);再在login.php的/body的上一行加一段代碼,如:
?php echo ‘script language=”text/javascript”alert(“‘ . $_SESSION[‘error_message’] . ‘”;/script’; ?即可。
php 登錄模塊
?php
if ($_GET[out]) {
SetCookie(“temp”, “”);
echo “scriptlocation.href=’./login_cookie.php’/script”;
}
if ($_POST[username] $_POST[password]) {
setcookie(‘name’, $_POST[username], time()+3600);
setcookie(‘pass’, md5($_POST[password]), time()+3600);
setcookie(‘temp’, “true”, time()+3600);
echo “scriptlocation.href=’./login_cookie.php’/script”;
}
if ($_COOKIE[name] $_COOKIE[pass] $_COOKIE[temp]) {
echo ‘login ok!bryour name is ‘.$_COOKIE[name].
‘bryour password is ‘.$_COOKIE[pass].
“bra href=’login_cookie.php?out=1’logout/a”;
} else {
?
form action=”” method=”post”
username:input type=”text” name=”username” value=”?=$_COOKIE[name]?”/br/
password:input type=”password” name=”password”/br/
input type=”submit” name=”login” value=”login”/br/
/form
?php } ?
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/244616.html