當註冊成功到登陸後進入我的中心,查看和修改本身的資料javascript
第一步:建立我的中心:php
<?php //定義個常量,用來受權調用includes裏面的文件
define('IN_TG',true); //定義個常量,用來指定本頁的內容
define('SCRIPT','member'); //引入公共文件
require dirname(__FILE__).'/includes/common.inc.php'; //是否正常登陸
if (isset($_COOKIE['username'])) { //獲取數據
$_rows=_fetch_array("SELECT tg_username,tg_sex,tg_face,tg_email,tg_url,tg_qq,tg_level,tg_reg_time FROM tg_user WHERE tg_username='{$_COOKIE['username']}'"); if($_rows){ /* $_username=$_rows['tg_username']; $_sex=$_rows['tg_sex']; */
$_html=array(); $_html['username']=$_rows['tg_username']; $_html['sex'] = $_rows['tg_sex']; $_html['face'] = $_rows['tg_face']; $_html['email'] = $_rows['tg_email']; $_html['url'] = $_rows['tg_url']; $_html['qq'] = $_rows['tg_qq']; $_html['reg_time'] = $_rows['tg_reg_time']; switch ($_rows['tg_level']){ case 0:
$_html['level'] = '普通會員'; break; case 1:
$_html['level'] = '管理員'; break; default:
$_html['level'] = '不是本地管理員'; } $_html = _html($_html); }else{ _alert_back('此用戶不存在!'); } }else{ _alert_back("非法登陸!"); } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多用戶留言系統--我的用戶中心</title>
<?php require ROOT_PATH.'includes/title.inc.php'; ?>
</head>
<body>
<?php require ROOT_PATH.'includes/header.inc.php'; ?>
<div id="member">
<?php require ROOT_PATH.'includes/member.inc.php'; ?>
<div id="member_main">
<h2>會員管理中心</h2>
<dl>
<dd>用戶名:<?php echo $_html['username']?></dd>
<dd>性 別:<?php echo $_html['sex']?></dd>
<dd>頭 像:<?php echo $_html['face']?></dd>
<dd>電子郵件:<?php echo $_html['email']?></dd>
<dd>主 頁:<?php echo $_html['url']?></dd>
<dd>QQ :<?php echo $_html['qq']?></dd>
<dd>註冊時間:<?php echo $_html['reg_time']?></dd>
<dd>身 份:<?php echo $_html['level']?></dd>
</dl>
</div>
</div>
<?php require ROOT_PATH.'includes/footer.inc.php'; ?>
</body>
</html>
require ROOT_PATH.'includes/member.inc.php'中的代碼:
<?php //防止惡意調用
if (!defined('IN_TG')) { exit('Access Defined!'); } ?>
<div id="member_sidebar">
<h2>中心導航</h2>
<dl>
<dt>賬號管理</dt>
<dt>
<a href="member.php">我的信息</a>
</dt>
<dt>
<a href="member_modify.php">修改資料</a>
</dt>
</dl>
<dl>
<dt>其餘管理</dt>
<dt>
<a href="#">短信查閱</a>
</dt>
<dt>
<a href="#">好友設置</a>
</dt>
<dt>
<a href="#">查詢花朵</a>
</dt>
<dt>
<a href="#">我的相冊</a>
</dt>
</dl>
</div>
相關的CSShtml
@CHARSET "UTF-8"; #member { width:auto; height:600px; border:2px solid #ccc; font-size:12px;
} #member h2 { text-indent:0; text-align:center; height:30px; line-height:30px;
} #member #member_sidebar { width:300px; height:500px; margin:15px; border:1px dashed #999; float:left;
} #member #member_sidebar dl { width:250px; background:red; margin:15px auto;
} #member #member_sidebar dl dt { height:40px; line-height:40px; background:#999; font-weight:bold; text-align:center; color:#fff;
} #member #member_sidebar dl dd { height:40px; line-height:40px; background:#eee; font-weight:bold; text-align:center;
} #member #member_sidebar dl dd a { display:block; color:#333; text-decoration:none;
} #member #member_sidebar dl dd a:hover { background:#ccc;
} #member #member_main { width:590px; height:500px; margin:15px; border:1px dashed #999; float:right;
} #member #member_main dl { width:500px; margin:15px auto; font-size:14px;
} #member #member_main dl dd { padding:10px 0; border-bottom:1px dashed #999;
}
我的中心建立後就是修改我的中心:java
<?php session_start(); //定義個常量,用來受權調用includes裏面的文件
define('IN_TG',true); //定義個常量,用來指定本頁的內容
define('SCRIPT','member_modify'); //引入公共文件
require dirname(__FILE__).'/includes/common.inc.php'; //修改資料及服務端的驗證函數是調用了註冊時使用的register.func.php 來驗證
if($_GET['action']=='modify'){ //echo '修改的資料有誤,請確認';
_check_code($_POST, $_SESSION['code']); include ROOT_PATH.'includes/register.func.php'; $_clean=array(); $_clean['password'] = _check_modify_password($_POST['password'],6); $_clean['sex']=_check_sex($_POST['sex']); $_clean['face'] = _check_face($_POST['face']); $_clean['email'] = _check_email($_POST['email'], 6, 40); $_clean['qq'] = _check_qq($_POST['qq']); $_clean['url'] = _check_url($_POST['url'], 40); //修改資料
if (empty($_clean['password'])){ _query("UPDATE tg_user SET tg_password='{$_clean['password']}', tg_sex='{$_clean['sex']}', tg_face='{$_clean['face']}', tg_email='{$_clean['email']}', tg_qq='{$_clean['qq']}'; tg_url='{$_clean['url']}' WHERE tg_username='{$_COOKIE['username']}' "); }else{ _query("UPDATE tg_user SET tg_password='{$_clean['password']}', tg_sex='{$_clean['sex']}', tg_face='{$_clean['face']}', tg_email='{$_clean['email']}', tg_qq='{$_clean['qq']}', tg_url='{$_clean['url']}' WHERE tg_username='{$_COOKIE['username']}' "); } //判斷是否修改
if(_affected_rows()==1){ _close(); _session_destroy(); _location('恭喜你,修改爲功', 'member.php'); }else{ _close(); _session_destroy(); _location('很遺憾,修改失敗', 'member_modify.php'); } } //是否正常登陸
if (isset($_COOKIE['username'])) { //獲取數據
$_rows=_fetch_array("SELECT tg_username,tg_sex,tg_face,tg_email,tg_url,tg_qq FROM tg_user WHERE tg_username='{$_COOKIE['username']}'"); if($_rows){ /* $_username=$_rows['tg_username']; $_sex=$_rows['tg_sex']; */
$_html=array(); $_html['username']=$_rows['tg_username']; $_html['sex'] = $_rows['tg_sex']; $_html['face'] = $_rows['tg_face']; $_html['email'] = $_rows['tg_email']; $_html['url'] = $_rows['tg_url']; $_html['qq'] = $_rows['tg_qq']; $_html = _html($_html); //性別選擇
if ($_html['sex'] == '男') { $_html['sex_html'] = '<input type="radio" name="sex" value="男" checked="checked" /> 男 <input type="radio" name="sex" value="女" /> 女'; } elseif ($_html['sex'] == '女') { $_html['sex_html'] = '<input type="radio" name="sex" value="男" /> 男 <input type="radio" name="sex" value="女" checked="checked" /> 女'; } //頭像選擇
$_html['face_html'] = '<select name="face">'; foreach (range(1,9) as $_num) { $_html['face_html'] .= '<option value="face/m0'.$_num.'.gif">face/m0'.$_num.'.gif</option>'; } foreach (range(10,64) as $_num) { $_html['face_html'] .= '<option value="face/m'.$_num.'.gif">face/m'.$_num.'.gif</option>'; } $_html['face_html'] .= '</select>'; }else{ _alert_back('此用戶不存在!'); } }else{ _alert_back("非法登陸!"); } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多用戶留言系統--我的用戶中心</title>
<?php require ROOT_PATH.'includes/title.inc.php'; ?>
<script type="text/javascript" src="js/code.js"></script>
<script type="text/javascript" src="js/member_modify.js"></script>
</head>
<body>
<?php require ROOT_PATH.'includes/header.inc.php'; ?>
<div id="member">
<?php require ROOT_PATH.'includes/member.inc.php'; ?>
<div id="member_main">
<h2>會員管理中心</h2>
<form method="post" action="?action=modify">
<dl>
<dd>用戶名:<?php echo $_html['username']?></dd>
<dd>密 碼:<input type="password" class="text" name="password"/>(*留空表示不修改)</dd>
<dd>性 別:<?php echo $_html['sex_html']?></dd>
<dd>頭 像:<?php echo $_html['face_html']?></dd>
<dd>電子郵件:<input type="text" class="text" name="email" value="<?php echo $_html['email']?>" /></dd>
<dd>主 頁:<input type="text" class="text" name="url" value="<?php echo $_html['url']?>" /></dd>
<dd>QQ :<input type="text" class="text" name="qq" value="<?php echo $_html['qq']?>" /></dd>
<dd>驗證碼:<input type="text" name="code" class="text yzm" /><img src="code.php" id="code"></img></dd>
<dd><input type="submit" class="submit" value="修改資料" /></dd>
</dl>
</form>
</div>
</div>
<?php require ROOT_PATH.'includes/footer.inc.php'; ?>
</body>
</html>
_check_modify_password:session
相對應的封裝函數:ide
/** * * @param unknown $_string * @param unknown $_min_num * @return NULL|string */
function _check_modify_password($_string,$_min_num){ //判斷密碼
if (! empty ( $_string )) { if (strlen ( $_string ) < $_min_num) { _alert_back ( '密碼不得小於' . $_min_num . '位!' ); } }else{ return null; } return sha1($_string); }
相關的CSS文件:函數
@CHARSET "UTF-8"; #member { width:auto; height:600px; border:2px solid #ccc; font-size:12px;
} #member h2 { text-indent:0; text-align:center; height:30px; line-height:30px;
} #member #member_sidebar { width:300px; height:500px; margin:15px; border:1px dashed #999; float:left;
} #member #member_sidebar dl { width:250px; background:red; margin:15px auto;
} #member #member_sidebar dl dt { height:40px; line-height:40px; background:#999; font-weight:bold; text-align:center; color:#fff;
} #member #member_sidebar dl dd { height:40px; line-height:40px; background:#eee; font-weight:bold; text-align:center;
} #member #member_sidebar dl dd a { display:block; color:#333; text-decoration:none;
} #member #member_sidebar dl dd a:hover { background:#ccc;
} #member #member_main { width:590px; height:500px; margin:15px; border:1px dashed #999; float:right;
} #member #member_main dl { width:500px; margin:15px auto; font-size:14px;
} #member #member_main dl dd { padding:10px 0; border-bottom:1px dashed #999;
} #member #member_main dl dd input.text { width:220px; height:19px; border:1px dashed #333; background:#fff;
} #member #member_main dl dd input.yzm { width:60px;
} #member #member_main dl dd img#code { position:relative; top:8px; cursor:pointer;
} #member #member_main dl dd input.submit { width:60px; height:22px; border:1px dashed #333; background:#fff; cursor:pointer;
}
客戶端驗證:post
調用了register.js 的代碼fetch
window.onload=function(){ code(); //表單驗證,客戶端
var fm=document.getElementsByTagName('form')[0]; fm.onsubmit=function(){ //密碼驗證
if(fm.password.value=''){ if (fm.password.value.length < 6) { alert('密碼不得小於6位'); fm.password.value = ''; //清空
fm.password.focus(); //將焦點以致表單字段
return false; } } //郵箱驗證
if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(fm.email.value)) { alert('郵件格式不正確'); fm.email.value = ''; //清空
fm.email.focus(); //將焦點以致表單字段
return false; } //QQ號碼
if (fm.qq.value != '') { if (!/^[1-9]{1}[\d]{4,9}$/.test(fm.qq.value)) { alert('QQ號碼不正確'); fm.qq.value = ''; //清空
fm.qq.focus(); //將焦點以致表單字段
return false; } } //網址
if (fm.url.value != '') { if (!/^https?:\/\/(\w+\.)?[\w\-\.]+(\.\w+)+$/.test(fm.url.value)) { alert('網址不合法'); fm.url.value = ''; //清空
fm.url.focus(); //將焦點以致表單字段
return false; } } //驗證碼驗證
if (fm.code.value.length != 4) { alert('驗證碼必須是4位'); fm.code.value = ''; //清空
fm.code.focus(); //將焦點以致表單字段
return false; } }; };