|
发表于 2011-11-20 14:42:12
|
显示全部楼层
本帖最后由 qi_ruo 于 2011-11-20 15:28 编辑
PHP复制代码 class Test extends CI_Controller {
public function __construct ()
{
parent ::__construct ();
$this->load->helper('url');
}
public function get_captcha ()
{
if ($this->input->is_ajax_request()) {
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url ().'captcha/'
);
$cap = create_captcha ($vals);
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
echo $cap['image'];
} else {
show_404 ();
}
}
public function captcha_form ()
{
$this->load->view('captcha_form');
}
} 复制代码
HTML复制代码 <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Captcha Form </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
function get_captcha() {
$.get(" <?php echo site_url('test/get_captcha');?>", function(data){
$('#captcha-image').html(data);
});
};
$(function(){
get_captcha();
$('#reload-captcha').click(get_captcha);
})
</script>
</head>
<body>
<form method="post">
<p id="captcha-image"></p>
<p><a href="javascript:void(0);" id="reload-captcha">Reload Captcha </a></p>
<p><input type="text" name="captcha" /></p>
<p><input type="submit" value="submit" /></p>
</form>
</body>
</html> 复制代码
|
|