|
想实现一个验证码功能
Controller:
<?php
/**
*验证登录的控制器
*
*/
class Login extends CI_Controller
{
public function __construct(){
parent::__construct();
$this->load->model('login_model');
}
public function login(){
$imgVcode = $this->login_model->getVcode();
$img = $imgVcode['image'];
return $img;
}
}
?>
Model
<?php
/**
* 登陆验证的model
*/
class Login_model extends CI_Model{
public function __construct(){
$this->load->helper("captcha");
$this->load->database();
}
public function getVcode(){
$vals = array(
'word' => rand(10000,100000),//验证码上显示的字符
'img_path' => './captcha/',//验证码保存路径
'img_url' => 'http://localhost/captcha/', //验证码图片url
'font_path' => './path/to/fonts/texb.ttf',//验证码上字体
'img_width' => '100',
'img_height' => 25,
'expiration' => 100,
'word_length' => 8,
'font_size' => 16,
'img_id' => 'Imageid',
'pool' => '23456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'color' => array(
'background' => array(255,255,255),
'border' => array(255,255,255),
'text' => array(0,0,0),
'grid' => array(255,40,40)
)
);
$cap = create_captcha($vals);
return $cap;
}
}
?>
页面:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>登陆</title>
</head>
<body>
<p style="font-size: 40px" align="center">欢迎来到BBS</p>
<form action="validate.php" method="post" name="form">
<center>
用户名:<input type="text" name="username" style="width: 150px" >
<br><br>
密 码:<input type="password" name="password" style="width: 150px">
<br><br>
验证码:<input type="text" name="validate" style="width: 100px">
<img src="<?php echo site_url('login/login'); ?>" alt="" onclick=this.src="<?php
echo site_url('login/login').'/' ?>"+Math.random() style="cursor:pointer;" title="看不清?再来一张吧"/>
<br><br>
<input type="submit" value="提交" style="width: 100px">
<input type="reset" value="重置" style="width: 100px">
</center>
</form>
</body>
<htfile:///C:\Users\ADMINI~1\AppData\Local\Temp\@IR3P(8S$C$Z$TY~5I{QEPC.gifml>
图片显示不出来,直接访问localhost/index.php?/login/login 是没有问题的,可以正常显示图片
需要怎么做?
谢谢!
|
|