Login.php代码
<?php
if (!defined('ROOT_PATH'))
exit('invalid request');
if (!defined('Copyright') || Copyright != '作者QQ:123954121')
exit('作者QQ:123954121');
include_once ROOT_PATH.'Manage/config/config.php';
if ($_SERVER["REQUEST_METHOD"] == 'POST')
{
if(isset($_POST['islogin'])&&$_POST['islogin']==1){
if ($ConfigModel['g_web_lock'] != 1) exit(back($ConfigModel['g_web_text']));
//瀏覽器檢測、只支持IE核心
if (!GetMsie()) exit(back($UserError));
//驗證用戶和密碼是否存在
$loginName = $_POST['loginName'];
$loginPwd = sha1($_POST['loginPwd']);
$db = new DB();
$sql = "SELECT * FROM `g_user` WHERE `g_name` = '{$loginName}' AND `g_password` = '{$loginPwd}' LIMIT 1 ";
$result = $db->query($sql, 1);
if ($result)
{
//判斷帳號是否已被停用
if ($result[0]['g_look'] == 3) exit(back($UserLook));
$uniqid = md5(uniqid());
$loginIp = GetIP();
$loginDate = date("Y-m-d H:i:s");
$sql = "UPDATE `g_user` SET `g_uid` = '{$uniqid}', `g_ip` = '{$loginIp}', `g_out` =1, `g_count_time`=now(),`g_state` =1 WHERE `g_name` = '{$loginName}' AND `g_password` = '{$loginPwd}' ";
$db->query($sql, 2);
$qqWryInfo = ROOT_PATH.'tools/IpLocationApi/QQWry.Dat';
$ip_s = ipLocation($loginIp, $qqWryInfo);
$sql = "INSERT INTO g_login_log (g_name, g_ip, g_ip_location, g_date) VALUES ('{$loginName}','{$loginIp}','{$ip_s}',now())";
$db->query($sql, 2);
$_SESSION['g_S_name'] = $result[0]['g_name'];
setcookie("g_user", base64_encode($loginName), 0, "/");
setcookie("g_uid", base64_encode($uniqid), 0, "/");
if( $_POST['banben']==2)
include_once ROOT_PATH.'validate.php';
else
include_once ROOT_PATH.'validate_us.php';
exit;
}
else
{
back($UserError);
exit;
}
}else{
//驗證碼匹配
if ($_POST['ValidateCode'] == $_SESSION['code'])
{
//驗證用戶和密碼是否存在
$loginName = $_POST['loginName'];
$loginPwd = sha1($_POST['loginPwd']);
$db = new DB();
$sql = "SELECT * FROM `g_user` WHERE `g_name` = '{$loginName}' AND `g_password` = '{$loginPwd}' LIMIT 1 ";
$result = $db->query($sql, 1);
if ($result)
{
echo 0;
exit;
}
else
{
echo 1;
exit;
}
}
else
{
echo 2;
exit;
}
}
}
else
{
// $num = array();
// for ($i=0; $i<4; $i++)
// {
// $num[$i] = rand(0,9);
// }
// $num = join('', $num);
// $_SESSION['code'] = $num;
}
?>
login.js代码
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, '');
}
function loadbg(){
var imgstr='';
for (var c = 0; c < 6; c++) {
imgstr += "<img src='" + LoginPic[c] + "' />"
}
$('#bg').html(imgstr);
$('#img').html('<img src=yzm.php />');
}
function rvcode(){
$('#img').html('');
}
function doLogin(){
if(validateForm()){
var loginName = $('input[name=loginName]').val();
var loginPwd = $('input[name=loginPwd]').val();
var ValidateCode = $('input[name=ValidateCode]').val();
$.ajax({
data:{'loginName':loginName,'loginPwd':loginPwd,'ValidateCode':ValidateCode},
url:'Login.php',
type:'post',
success:function(data){
if(data=='0'){
var banben=1;
$(':radio').each(function(){
if(this.checked) banben=this.value;
})
document.forms['lform'].banben.value = banben;
document.forms['lform'].loginName.value = loginName;
document.forms['lform'].loginPwd.value = loginPwd;
document.forms['lform'].submit();
}else if(data=='1'){
alert('用户名或者密码错误');
$('input[name=loginName]')[0].select();
$('input[name=loginPwd]').val('');
rvcode();
}else if(data=='2'){
alert('验证码错误');
rvcode();
$('input[name=ValidateCode]')[0].select();
}else{
alert(data);
rvcode();
}
}
})
}
}
function validateForm() {//表单验证准则
var form = document.forms['login_form'];
var name = form.loginName.value.trim();
form.name.value = name;
var loginPwd = form.loginPwd.value.trim();
var vcode = form.ValidateCode.value.trim();
form.loginPwd.value = loginPwd;
if (!(/^[a-z0-9A-Z][a-z0-9A-Z_]{0,11}$/.test(name))) {
alert('账号由1-12位英文字母、数字、下划线组成,且第一位不能是下划线');
form.loginName.focus();
return false;
}
if (!(/^[0-9a-zA-Z]{6,16}$/.test(loginPwd))) {
alert('密码由6-16位英文字母、数字字符组成');
form.loginPwd.focus();
return false;
}
if (vcode.length != 4) {
alert('验证码由4位数字组成');
form.ValidateCode.focus();
return false;
}
if (!(/^\d{4}$/.test(vcode))) {
alert('验证码由4位数字组成');
form.ValidateCode.focus();
return false;
}
return true;
}
function initValidatePage(){
var dialog = $.dialog({
title: '历史公告',
content: 'url:/loadHistory.php',
lock : true,
max : false,
min : false,
button: [{
name: '确定',
callback: function () {
return true;
},
focus: false
}]
});
$('#agree').bind('click',function(){
document.form1.submit();
return false;
})
$('#disagree').bind('click',function(){
top.location='/userlib/quit.php';
return false;
})
}
$(document).keydown(function(event) {
if (event.keyCode == 13) {
try{$('#loginBtn').trigger('click');}catch(E){}
}
});