首页 > 开发 > AJAX > 正文

ECSHOP中实现ajax弹窗登录功能

2024-09-01 08:27:21
字体:
来源:转载
供稿:网友

在上篇文章给大家介绍了使用openSpeDiv方法实现Ecshop登录弹窗框效果,大家点击参考下

下面介绍如何实现AJAX弹窗登录。

在ECSHOP中的user.PHP中有处理用户登录的请求。

/* 处理 ajax 的登录请求 */ elseif ($action == 'signin') {  include_once('includes/cls_json.php');  $json = new JSON;  $username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : '';  $password = !empty($_POST['password']) ? trim($_POST['password']) : '';  $captcha = !empty($_POST['captcha']) ? json_str_iconv(trim($_POST['captcha'])) : '';  $result = array('error' => 0, 'content' => '');  $captcha = intval($_CFG['captcha']);  if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)  {   if (empty($captcha))   {    $result['error'] = 1;    $result['content'] = $_LANG['invalid_captcha'];    die($json->encode($result));   }   /* 检查验证码 */   include_once('includes/cls_captcha.php');   $validator = new captcha();   $validator->session_word = 'captcha_login';   if (!$validator->check_word($_POST['captcha']))   {    $result['error'] = 1;    $result['content'] = $_LANG['invalid_captcha'];    die($json->encode($result));   }  }  if ($user->login($username, $password))  {   update_user_info(); //更新用户信息   recalculate_price(); // 重新计算购物车中的商品价格   $smarty->assign('user_info', get_user_info());   $ucdata = empty($user->ucdata)? "" : $user->ucdata;   $result['ucdata'] = $ucdata;   $result['content'] = $smarty->fetch('library/member_info.lbi');  }  else  {   $_SESSION['login_fail']++;   if ($_SESSION['login_fail'] > 2)   {    $smarty->assign('enabled_captcha', 1);    $result['html'] = $smarty->fetch('library/member_info.lbi');   }   $result['error'] = 1;   $result['content'] = $_LANG['login_failure'];  }  die($json->encode($result)); } 

把上面这段代码修改一下,删掉需要验证码的部分

改成

/* 处理 ajax弹窗登录请求 */ elseif ($action == 'ajax_login') {  include_once('includes/cls_json.php');  $json = new JSON;  $username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : '';  $password = !empty($_POST['password']) ? trim($_POST['password']) : '';  $result = array('error' => 0, 'content' => '');  $captcha = intval($_CFG['captcha']);  if ($user->login($username, $password))  {   update_user_info(); //更新用户信息   recalculate_price(); // 重新计算购物车中的商品价格   $smarty->assign('user_info', get_user_info());   $ucdata = empty($user->ucdata)? "" : $user->ucdata;   $result['ucdata'] = $ucdata;   $result['content'] = $smarty->fetch('library/member_info.lbi');  }  else  {   $result['error'] = 1;   $result['content'] = $_LANG['login_failure'];  }  die($json->encode($result)); }             
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表