|
本帖最后由 liaomars 于 2012-11-20 13:45 编辑
我把ci的原session类,换成了Hex大的session类了.但是我输出session的值的时候是空的.这是代码中的一小段代码.$code是有值的
PHP复制代码
<?php
/*
* 调用验证码
* @author liaoyunyu@gmail.com
* 2012-07-12
*/
class Captcha extends CI_Controller {
function __construct () {
parent ::__construct ();
//$this->load->library('Authcode');
$this->load->library('captca');
$this->load->library('session');
}
//显示图片
function show (){
$this->captca->doimg();
}
function code (){
echo $code= $this->captca->getCode();
// echo $this->session->userdata('auth_code');
$this->session->set_userdata('auth_code', $code);//设置session
}
}
?>
复制代码
这上面是session输入的
这下面是取出session值
PHP复制代码
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Reg extends CI_Controller {
function __construct () {
session_start();
parent ::__construct ();
$this->load->helper('url'); //加载帮助类的url类
[color =#ff0000]$this->load->library('session'); //加载帮助类的url类
}
public function index () {
$this->load->view('reg_html');
$this->load->view('footer');
}
//用户提交的数据保存
function save () {
[color =#ff0000] //这里需要session的值
if ([color =#ff0000]$_POST['verifycode'] == $this->session->userdata('auth_code')) {
$data = array(
"user" => $this->input->post('AccountName'),
"pass" => md5($this->input->post('AccountPass')),
"email" => $this->input->post('Email'),
"contact" => $this->input->post('LinkMan'),
"tel" => $this->input->post('tel'),
);
$this->load->model('union_model', '', true); //载入模型
$user_id = $this->union_model->insert('user', $data);
$img_thumb=$this->getthumb($this->input->post('SiteUrl'));
$data2 = array(
'name' => $this->input->post('SiteName'),
'url' => $this->input->post('SiteUrl'),
'type' => $this->input->post('SiteType'),
'des' => $this->input->post('SiteDes'),
'user_id' => $user_id,
'addtime' => time(),
);
$web_id = $this->union_model->insert('web', $data2);
if ($web_id) {
$addcodeurl = site_url ('reg/addcode/' . $web_id);
redirect ($addcodeurl);
}
} else {
echo '验证码输入不正确!';
}
}
function addcode () {
$web_id = $this->uri->segment(3, 0);
$url = "http://union.huituan.com/code/jscode/$web_id";
$data['url'] = $url;
$this->load->view('head', $data);
$this->load->view('reg_2_html');
$this->load->view('footer');
}
//取得url的首页缩略图片
function getthumb ($url) {
ob_start();
passthru("/sbin/wkhtmltoimage $url -"); //把wkhtmltoimage 的命令发送到linux.
$content = ob_get_contents(); //取到生成的数据流
$imgfile = '/var/www/union/index_img/' . $url . "jpg";
file_put_contents($imgfile, $content); //把数据流写入文件中
return $imgfile;
}
//图片裁剪
function cut_img ($img,$toimg) {
// $img = "test.jpg"; //源图片
$toW = "135"; //缩略图宽
$toH = "90"; //缩略图高
//$toimg = "123.jpg"; //生成缩略的图片
$imginfo = getimagesize($img); //取得原始图片信息
//print_r($img);
switch ($imginfo[2]) {
case '1':
$im = imagecreatefromgif($img);
break;
case '2':
$im = imagecreatefromjpeg($img);
break;
case '3':
$im = imagecreatefrompng($img);
break;
}
$srcW = $imginfo[0];
$srcH = $imginfo[1];
$toWH = $toW / $toH; //缩略图比例
$srcWH = $srcW / $srcH; //原图比例
//如果缩略图比例小于原始图的比例
if ($toWH <= $srcWH) {
$ftoH = $toH; //现在的高度就是缩略图的高度
$ftoW = $ftoH * ($srcW / $srcH); //宽度等于缩略图高度*原始图比例
} else {
//如果缩略图比例大于原始图的比例,
$ftoW = $toW; //
$ftoH = $ftoW * ($srcH / $srcW);
}
$canvas = imagecreatetruecolor($ftoW, $ftoH); //创建画布
imagecopyresized($canvas, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); //拷贝原图片到新创建的画布上
$ext = end(explode('.', strtolower($img))); //取得图片的后缀
//输出图像
if ($ext == 'jpg') {
imagejpeg($canvas, $toimg, 100);
} elseif ($ext == 'gif') {
imagegif($canvas, $toimg, 100);
} else {
imagepng($canvas, $toimg, 100);
}
imagedestroy($canvas);
imagedestroy($im);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
复制代码
|
|