登录注册案例一
这个项目只有登录,貌似是我接触的第一个有登录的项目,写的与想死的心都有了,全程看着别人敲。。。。。

又是熟悉的mask遮罩
<div id="mask" style="display: none;">
<div id="artl">
<div class="a-top">
<h4>XX登录</h4>
<div id="close"></div>
</div>
<form>
<div class="form_control1">
<label>手机号码:</label><input class="required1" type="text" name="phone" id="phone">
</div>
<div class="form_control1">
<label>密 码:</label><input class="required1" type="password" name="password" id="password">
</div>
<input type="button" id="logins" value="登录" class="login">
</form>
</div>
</div>
JS弹出控制与表单验证
<script type="text/javascript"> $(".checked-href").click(function(){ $("#mask").fadeIn(); $("#close").click(function(){ $("#mask").fadeOut(); }) }) </script> <script> $(function () { $("#logins").click(function(){ var phone = $("#phone").val(); var password = $("#password").val(); if (phone=="") { alert("手机不能为空") $("#phone").focus(); return } if(password==""){ alert("密码不能为空") $("#password").focus(); return } var myreg=/^1(3|5|7|8)\d\d\d\d\d\d\d\d\d$/; if(!myreg.test(phone)){ alert("手机格式不正确") $("#phone").focus(); return } $.post("{PURL('checked/login')}",{ 'phone':phone,'password':password },function(data){ if (data == 1) { window.location.href="{PURL('checked')}"; }else{ alert(data) } }) }) }) </script>
php登录验证部分的代码
public function login(){ $phone = $_POST['phone']; $password = md5($_POST['password']); $user = $this->db->getOne("SELECT * FROM ".TABLE_PREFIX."user WHERE phone = '$phone' "); if (empty($user)) { echo "授权代理不存在"; exit(); } if ($password!=$user['password']) { echo "密码错误"; exit(); } //打开session Session_start(); //定义session变量 $_SESSION['user_id'] = $user['id']; echo "1"; }
----------------------------------------------割---------------------------------------------------------------------
这里没有注册但是有个修改代码
php部分
public function modifyPwd(){ // $phone = $_POST['phone']; $user_id=$_SESSION['user_id']; $user = $this->db->getOne("SELECT * FROM ".TABLE_PREFIX."user WHERE id = '$user_id' "); $oldpassword = md5($_POST['oldpsd']); $password1 = md5($_POST['psd1']); if ($oldpassword!=$user['password']) { echo "原密码错误"; exit(); } $this->db->exe("UPDATE " . TABLE_PREFIX . "user SET password = '$password1' WHERE id = '$user_id'"); echo "1"; }
html部分
<div id="content2" style="display: none;"> <form> <div class="form_control"> <label>原密码:</label><input class="required" type="password" id="oldpassword" name="oldpassword"> <div style="display: inline" id="tip1"></div> </div> <div class="form_control"> <label>新密码:</label><input class="required" type="password" id="password1" name="password1"> <div style="display: inline" id="tip2"></div> </div> <div class="form_control"> <label>确认密码:</label><input class="required" type="password" id="password2" name="password2"> <div style="display: inline" id="tip3"></div> </div> <div> <input type="button" value="修改" class="alter" id="xgbtn"> </div> </form> </div>
js表单验证以及ajax提交
$("#xgbtn").click(function(){
// console.log(1);
var oldpsd = $("#oldpassword").val();
var psd1 = $("#password1").val();
var psd2 = $("#password2").val();
var num1=$("#password1").val().length;
var num2=$("#password2").val().length;
if (oldpsd === "") {
$("#tip1").html("原密码不能为空");
$("#oldpassword").focus();
return
}
if (psd1 == "") {
$("#tip1").html("新密码不能为空");
$("#password1").focus();
return
}
if(psd1!=psd2) {
$("#tip3").html("两次密码输入不一致");
$("#password1").focus();
return
}else{
$("#tip3").html("输入正确");
}
$.post("{PURL('checked/modifyPwd')}",{ 'oldpsd':oldpsd,'psd1':psd1 },function(data){
if (data == 1) {
alert("密码修改成功")
window.location.href="{PURL('checked')}";
}else{
alert(data)
}
})
})
有登陆也应该有登出,【不然以为是SAO吗……
html部分没什么好记录的,一个登出按钮,给个ID---logout
js传值
$("#logout").click(function(){
$.post("{PURL('checked/logout')}",function(data){
if (data == 2) {
alert("退出成功,点击返回首页!");
window.location.href="{PURL('index')}";
}
})
})
php接收
public function logout(){ unset($_SESSION['user_id']); echo '1'; }
暂时整理这样,应该没有遗漏了_(:з」∠)_

浙公网安备 33010602011771号