ecshop登陆的时候,很多情况下,为了提高用户体验,或者方便用户登陆。我们可以在用户退出的时候,记录他们的登陆名称。
下次登陆的时候,只需要填写密码就可以了。
思路:
只需要 在每次登陆的时候 写一个cookie 存用户名
然后每次打开登陆页面的时候 查找并显示这个用户名就行了
user.php
1,setcookie('username',$username,time()+24*3600*30);//添加cookie保存时间
2,$smarty->assign('username', $_COOKIE['username']);//存cookie的值,用于保存登录的值
user_password.dwt
3,增加value="{$username}" 的值 用于登录
<input name="username" type="text" size="25" value="{$username}" class="inputBg" /></td>
/* 2用户登录界面 */
elseif ($action == 'login')
{
if (empty($back_act))
{
if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
else
{
$back_act = 'user.php';
}
}
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$GLOBALS['smarty']->assign('enabled_captcha', 1);
$GLOBALS['smarty']->assign('rand', mt_rand());
}
$smarty->assign('username', $_COOKIE['username']);//保存cookie的值,用于登录
$smarty->assign('back_act', $back_act);
$smarty->display('user_passport.dwt');
}
/* 1处理会员的登录 */
elseif ($action == 'act_login')
{
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';
$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($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
}
if ($user->login($username, $password,isset($_POST['remember'])))
{
update_user_info();
recalculate_price();
setcookie('username',$username,time()+24*3600*30);//添加cookie保存时间
$ucdata = isset($user->ucdata)? $user->ucdata : '';
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
else
{
$_SESSION['login_fail'] ++ ;
show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
}
<!--#3登录界面 start-->
<!-- {if $action eq 'login'} -->
<div class="usBox clearfix">
<div class="usBox_1 f_l">
<div class="logtitle"></div>
<form name="formLogin" action="user.php" method="post" onSubmit="return userLogin()">
<table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
<tr>
<td width="15%" align="right">{$lang.label_username}</td>
<td width="85%"><input name="username" type="text" size="25" value="{$username}" class="inputBg" /></td>
</tr>
<tr>
<td align="right">{$lang.label_password}</td>
<td>
<input name="password" type="password" size="15" class="inputBg"/>
</td>
</tr>
<!-- 判断是否启用验证码{if $enabled_captcha} -->
<tr>
<td align="right">{$lang.comment_captcha}</td>
<td><input type="text" size="8" name="captcha" class="inputBg" />
<img src="captcha.php?is_login=1&{$rand}" alt="captcha" style="vertical-align: middle;cursor: pointer;" onClick="this.src='captcha.php?is_login=1&'+Math.random()" /> </td>
</tr>
<!--{/if}-->
<tr>
<td colspan="2"><input type="checkbox" value="1" name="remember" id="remember" /><label for="remember">{$lang.remember}</label></td>
</tr>
<tr>
<td> </td>
<td align="left">
<input type="hidden" name="act" value="act_login" />
<input type="hidden" name="back_act" value="{$back_act}" />
<input type="submit" name="submit" value="" class="us_Submit" />
</td>
</tr>
<tr><td></td><td><a href="user.php?act=qpassword_name" class="f3">{$lang.get_password_by_question}</a> <a href="user.php?act=get_password" class="f3">{$lang.get_password_by_mail}</a></td></tr>
</table>
</form>
</div>
<div class="usTxt">
<strong>{$lang.user_reg_info[0]}</strong> <br />
<strong class="f4">{$lang.user_reg_info[1]}:</strong><br />
<!-- {if $car_off eq 1} -->
{$lang.user_reg_info[2]}<br />
<!--{/if}-->
<!-- {if $car_off eq 0} -->
{$lang.user_reg_info[8]}<br />
<!--{/if}-->
{$lang.user_reg_info[3]}:<br />
1. {$lang.user_reg_info[4]}<br />
2. {$lang.user_reg_info[5]}<br />
3. {$lang.user_reg_info[6]}<br />
4. {$lang.user_reg_info[7]} <br />
<a href="user.php?act=register"><img src="images/bnt_ur_reg.gif" /></a>
</div>
</div>
<!--{/if}-->
<!--#登录界面 end-->

本文介绍了如何在ECShop中实现会员登录时自动填充用户名的功能,以提升用户体验。通过在用户退出时设置一个包含用户名的cookie,下次用户打开登录页面时,系统会自动读取该cookie并填充到用户名输入框,用户只需输入密码即可完成登录。

2378

被折叠的 条评论
为什么被折叠?



