我已经在godaddy托管中使用以下代码创建了两个codeignter控制器 Mysession.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mysession extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->database();
$this->load->library('session');
$this->load->helper('url');
}
public function index()
{
$this->load->library('session');
$this->session->set_userdata('fullname', 'David Beckham');
echo "<a href='".base_url()."index.php/mysession2'>Click here </a>";
}
}
下一个控制器是 Mysession2.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mysession2 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->database();
$this->load->library('session');
$this->load->helper('url');
}
public function index()
{
$this->load->library('session');
echo $this->session->userdata('fullname');
}
}
我对这些文件的假设http://goldmarktravel.com.au/index.php/mysession可能会将会话名称fullname设置为值“david beckham”,当我尝试访问http://goldmarktravel.com.au/index.php/mysession2时,它可能会显示该值。但它没有显示任何数据。除了godaddy托管之外,它在其他服务器上运行良好。
答案 0 :(得分:1)
试试这个
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '.yourdoamin.com';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
而是在每个控制器上加载库,您可以在config / autoload.php上自动加载它
$autoload['libraries'] = array('session');
答案 1 :(得分:-1)
$config['sess_save_path'] = BASEPATH. 'cache/sessions/';