|
JS如下
function codess()
{
var el =document.getElementById("codeg");
el.src="<?php echo site_url(index/code/'.rand(1,10000));?>";
}
VIEW
<img src="<?php echo site_url(index/code');?>" alt="点击刷新" class="codes" id="codeg" />
控制器
function code(){
$id=1;
if($id==1){
$this->load->library('codes');
echo $this->codes->get();
}
}
验证码类
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//-------------------------------------
// 文件说明:验证码
// 载入Codes $this->load->library('codes');
// 直接打印就可以了 echo $this->codes->get();
//-------------------------------------
class Codes{
function get() {
$randnum = '';//**,PHP也得先定义?
$width = 92; //定义验证码的宽和高
$hight = 22;
session_start();
for($i=0;$i<4;$i++){
$randnum .= dechex(rand(1,15));
}
$_SESSION['codes'] = $randnum;
$im = imagecreatetruecolor($width,$hight);
//设置颜色
imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
$nmsg = $randnum;
//文字输出
imagestring($im,rand(1,6),rand(1,50),rand(1,5),$nmsg,$te);
header("pragma:no-cachern");
header("Cache-Control:no-cachern");
header("Expires:0rn");
//输出图片
header("Content-type: image/jpeg");
imagejpeg($im);
}
}
我的问题是:为什么我第一次点刷新有反映,第二次就没了呢? |
|