Login (Ajax submit data and background check)

Source: Internet
Author: User

1. Front Desk Ajax Data submission

<form id= "Login_form" action= "" method= "POST" >
<div class= "Login_frame" style= "position:relative";>
<div class= "Login_gl" style= "margin-top:35px;" >
<span class= "LOGIN_WZ" > Backend Management system </span>
</div>

<div class= "Login_user" >
<input id= "username" name= "username" type= "text" placeholder= "Please enter your username" value= "" style= "WIDTH:100%;HEIGHT:32PX; Border-style:none;font-size:16px;color: #959595; " />
</div>

<div class= "Login_user" >
<input id= "password" name= "password" type= "password" placeholder= "Please enter your password" value= "" style= "width:100%;height:32px ; Border-style:none;font-size:16px;color: #959595; " />
</div>

<div id= "login_btn" class= "Login_log" >
<span style= "FONT-SIZE:16PX;" > Login </span>
</div>
</div>
</form>
</div>
<script type= "Text/javascript" >
$ ("#login_btn"). Click (function () {
var username = $.trim ($ ("#username"). Val ());
var password = $.trim ($ ("#password"). Val ());
if (username = = "") {
Alert ("Please enter user name");
return false;
}else if (password = = "") {
Alert ("Please enter password");
return false;
}
Ajax to server-side verification
var data= {Username:username,password:password};

$.ajax ({
Type: "POST",
URL: "__controller__/check_login",
Data:data,
DataType: ' JSON ',
Success:function (msg) {
Alert (msg);
if (msg==1) {
Window.location.href = "{: U (' index/personal ')}";
}else{
Alert ("Login failed, please try again!");
}
}
});
});
</script>

2. Background check:

* */
Public Function Check_login () {
$password =i (' Param.password ');
$username =i (' param.username ');
$data ["Name"]= $username;
$user =m (' systemuser ');
$list = $user->where ($data)->find ();
$return = 0;
if ($list! = "") {
if ($list [' Password ']==md5 ($password) && $list [' status '] = = 1) {
Logon time and login IP
$public = new Publiccontroller ();
$lastlogonip = $public->ip_address ();

$time = $time =date ("y-m-d h:i:s", Time ());
$where =array (' id ' = + $list [' id ']);

$user->where ($where)->save (Array (' lastlogonip ' = $lastlogonip, ' lastlogontime ' = $time));
$this->login ($list);
$return =1;//Login Successful
}
}else{
$return =2;//Logon Failure
}
$this->ajaxreturn ($return);
}

3. Sign Out:

Sign out:<a href= "{: U (' Login/login ')}"> <img src= "/public/images/ Tuichu.png "> </a>

Login (Ajax submit data and background check)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.