我有一个问题,我有一个用 PHP 设计的表单登录,在 Ajax 中验证,表单登录工作得很好,但是我需要为用户类型(管理员、用户)添加一个验证,并且我已经修改了我的代码,如下所示:
$.ajax({
type: 'POST',
url: 'log.inout.ajax.php',
data: 'login_username=' + $('#login_username').val() + '&login_userpass=' + $('#login_userpass').val(),
success:function(msj){
if ( msj == 1 ){
$('#alertBoxes').html('<div class="box-success"></div>');
$('.box-success').hide(0).html('Validacion Completa, Bienvenido al Sistema');
$('.box-success').slideDown(timeSlide);
setTimeout(function($tipo){
if ($tipo=='ADMIN'){
window.location.href = "../Main2/Index.php";
}else{
window.location.href = "../Main1/Index.php";
}
},(timeSlide + 500));
}
else{
$('#alertBoxes').html('<div class="box-error"></div>');
$('.box-error').hide(0).html('Datos Incorrectos, No Tiene Acceso al Sistema ');
$('.box-error').slideDown(timeSlide);
}
$('#timer').fadeOut(300);
},
error:function(){
$('#timer').fadeOut(300);
$('#alertBoxes').html('<div class="box-error"></div>');
$('.box-error').hide(0).html('Ha ocurrido un error durante la ejecución');
$('.box-error').slideDown(timeSlide);
}
});
问题是变量“$type”没有验证 AJAX,所以我需要你的帮助来解决这个问题
这是表单的验证文件:
<?php
session_start();
$user = $_POST['login_username'];
$pwd = $_POST['login_userpass'];
if ( !isset($_SESSION['username']) && !isset($_SESSION['userid']) ){
if ( $idcnx = mssql_connect('(local)','sa','.') ){
if ( mssql_select_db('DB_Demo',$idcnx) ){
$sql = "SELECT [USER],PASSWD,NOMBRE,APELLIDOP,TIPO FROM T_LOGIN WHERE [USER] ='$user' AND PASSWD ='$pwd'";
if ( $res = mssql_query($sql) ){
if ( mssql_num_rows($res) == 1 ){
$user = mssql_fetch_array($res);
$_SESSION['userid'] = $user[0];
$_SESSION['username'] = $user[1];
$_SESSION['unombre'] = $user[2];
$_SESSION['uapellido'] = $user[3];
$_SESSION['utipo'] = $user[4];
$tipo = $_SESSION['utipo'];
$_SESSION['autentificado']= 'SI';
$_SESSION['ultimoAcceso']= date('Y-n-j H:i:s');
echo 1;
}else{
echo 0;
}
}
else{
echo 0;
}
}
mssql_close($idcnx);
}
else{
echo 0;
}
}
else{
echo 0;
}
?>
谢谢...