如下情况验证码部分代码如何写以及写在哪里

WBOY
Release: 2016-06-13 13:43:56
Original
1105 people have browsed it

如下情况验证码部分代码怎么写以及写在哪里?
我想实现,某网站账号登陆页面中,有输入账号和密码的地方,如果账号或密码没有输入或者输入错误的时候会显示一个让用户输入验证码的输入框以及验证码数字,我想问的是这个验证码这个怎么判断啊?怎么判断有没有输入以及输入是否正确,这些代码写在哪里好啊?

因为起初只有账号和密码输入的地方,后来用jquery show出验证码那一块。

部分代码如下
$username = get_input('username');
$password = get_input("password");
$captcha = get_input('captcha_input');

$result = false;

if (!empty($username) && !empty($password)) 
{
if ($user = authenticate($username,$password)) 
{
$result = login($user, $persistent);
}
}
if ($result) 
{
system_message(elgg_echo('loginok'));

else 
{
$_SESSION['test'] = '123';

$error_msg = elgg_echo('loginerror');
}

前端代码
if ($_SESSION['test'] == '123')
{
?>
<script><br /> $('.captcha').show(); //用session判断账号有没有输入错误,如果输入错误就显示验证码那一块<br /></script>
}

------解决方案--------------------
那你用ajax来判断吧,验证错误用js显示验证码框 ~
------解决方案--------------------
如果有session['scode'],就验证验证码是否正确。
如果用户名密码为空或者错误,显示验证码flag为true,模板输出验证码
不是show,直接前端输出的时候就加载。如果要用js,也是prepend,如果只是hide、show,那么这个验证码session是一定存在的。
------解决方案--------------------
应该是你几次输出账户密码错误,才会出现那个那个验证码吧。如果你想根据输出用户名和密码,来显示验证码,那还不如直接加上验证码。不然你这么做不是多此一举吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!