Extjs+PHP实现登陆页面

HTML页面

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Extjs登陆对话框</title>
<script type="text/javascript" src="adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-all.js"></script>
<link type="text/css" href="resources/css/ext-all.css" rel="stylesheet">
</head>
<style type="text/css">
#btnShow{text-align: center; padding-top:200px; vertical-align:middle}
</style>
<body style="background:#C6D4E4;">
<div id="btnShow"></div>

<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
var loginPanel = new Ext.form.FormPanel({
              id:"loginPanel",
              width: 300,
              labelWidth: 100,
              frame:true,
              items:[{
              xtype:"textfield",
              id:"UserName",
              allowBlank: false,
              blankText:'用户名不能为空',
              fieldLabel:"用户名"
              },{
              xtype:"textfield",
              allowBlank: false,
              blankText:'密码不能为空',
              inputType: 'password',
              id:"Password",
              fieldLabel:"密&nbsp;&nbsp;&nbsp;码"
              }]       
         });
         
         var loginWindow;
         if(!loginWindow)
         {
             loginWindow = new Ext.Window({
                  id:"loginWindow",
                  title:"登陆窗口",
                  width:300,
                  resizable:false,
                  closable:false,
                  items:
                  [
                     loginPanel
                  ],
                  buttons:
                  [
                      {xtype:"button",text:"确定",handler:validatorData},
                      {xtype:"button",text:"取消",handler:exit}
                  ]
             });
         }
         loginWindow.show();
        
         function exit()
         {
         Ext.Msg.confirm("提示", "确定要退出吗?", function(btn, txt){
               if (btn == 'yes')
                window.close();
               else
                return;
              });
         }
        
         function validatorData()
         {
             var UserName = Ext.getCmp("UserName").getValue();
             var Password = Ext.getCmp("Password").getValue();
             if(Ext.util.Format.trim(UserName)=="" || Ext.util.Format.trim(Password)=="")
             {
                 Ext.Msg.alert("警告","请正确输入数据,用户名和密码都不能够为空!");
                 return;
             }
             Ext.Ajax.request
             ({
                  url:"handlelogin.php", //请求的地址
                  params:{Checked:"1",UserName:UserName,Password:Password},//发送的参数
                  success:function(response,option)
                  {
                      var obj = Ext.util.JSON.decode(response.responseText);//返回的信息
                      if(obj.success==true)
                      {
                          Ext.Msg.alert("信息提示","你登陆成功了!");
                          //清除输入框
                          Ext.getCmp("UserName").setValue("");
                          Ext.getCmp("Password").setValue("");
                          loginWindow.hide();
                      }
                      else
                      {
                          Ext.Msg.alert("信息提示","你登陆失败了!");
                          Ext.getCmp("UserName").setValue("");
                          Ext.getCmp("Password").setValue("");
                      }
                  },
                  failure:function()
                  {
                      Ext.Msg.alert("信息提示","你登陆出现异常了!");
                  }
             });
         }
        
     });
</script>
</body>
</html>

PHP 脚本

<?php
session_start();

$checked = $_REQUEST["Checked"];
$username = $_REQUEST["UserName"];
$Password = $_REQUEST["Password"];

$connection = mysql_connect("localhost", "root", "");
$sql = 'SELECT * from palog.users where username = "'.$username.'" and password="'.$Password.'"';
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if ($num == 0)
{
$infor['success'] = false;
}

if ($checked)
{
if (empty($username) || empty($Password))
{
    $infor['success'] = false;
}else
{
    if ($username == 'admin' && $Password == 'admin')
    {
     $infor['success'] = true;
     $_SESSION['username'] = $username;
     $_SESSION['password'] = $Password;
    }else
    {
     $infor['success'] = false;
    }
}

$json_string = json_encode($infor);

echo $json_string;
}
?>

你可能感兴趣的:(PHP,ExtJs,登陆)