我有两个控制器
1-connect facebook
2-connect create
当有人想要注册时,点击 connect_facebook.php ,控制器获取他的信息数据并在会话中设置,填写表格并发送数据到 connect_create.php 。 问题是connect_create控制器无法看到会话,为什么?
<?php
/*
* Connect_facebook Website
*/
class Connect_facebook extends Website {
/**
* Constructor
*/
function __construct() {
parent::__construct();
// Load the necessary stuff...
$this->load->config('account');
$this->load->helper('form');
$this->load->helper(array('language', 'ssl', 'url'));
$this->load->library(array('authentication', 'facebook_lib'));
$this->load->model(array('account_model', 'account_facebook_model'));
$this->load->language(array('general', 'sign_in', 'account_linked', 'connect_third_party'));
}
function index() {
// Enable SSL?
maintain_ssl($this->config->item("ssl_enabled"));
// Check if user is signed in on facebook
if ($this->facebook_lib->user) {
// Check if user has connect facebook to a3m
if ($user = $this->account_facebook_model->get_by_facebook_id($this->facebook_lib->user['id'])) {
// Check if user is not signed in on a3m
if (!$this->authentication->is_signed_in()) {
// Run sign in routine
$this->authentication->sign_in($user->account_id);
}
$user->account_id === $this->session->userdata('account_id') ? $this->session->set_flashdata('linked_error', sprintf(lang('linked_linked_with_this_account'), lang('connect_facebook'))) : $this->session->set_flashdata('linked_error', sprintf(lang('linked_linked_with_another_account'), lang('connect_facebook')));
redirect('users/account_linked');
}
// The user has not connect facebook to a3m
else {
// Check if user is signed in on a3m
if (!$this->authentication->is_signed_in()) {
// Store user's facebook data in session
$this->session->set_userdata('connect_create', array(array('provider' => 'facebook', 'provider_id' => $this->facebook_lib->user['id']), array('fullname' => $this->facebook_lib->user['name'], 'firstname' => $this->facebook_lib->user['first_name'], 'lastname' => $this->facebook_lib->user['last_name'], 'gender' => $this->facebook_lib->user['gender'], 'email' => $this->facebook_lib->user['email'],
// not a required field, not all users have it set
'picture' => 'http://graph.facebook.com/' . $this->facebook_lib->user['id'] . '/picture/?type=large' // $this->facebook_lib->user['link']
)));
// send this data to the user submit form
$data['locale'] = $this->facebook_lib->user['locale'];
$data['session'] = $this->session->userdata('connect_create');
$data['facebook_id'] = $this->facebook_lib->user['id'];
$data['username'] = $this->facebook_lib->user['name'];
$data['gender'] = $this->facebook_lib->user['gender'];
$data['email'] = $this->facebook_lib->user['email'];
$this->view('site/connect_create', $data);
} else {
// Connect facebook to a3m
$this->session->userdata('account_id');
$this->session->set_flashdata('linked_info', sprintf(lang('linked_linked_with_your_account'), lang('connect_facebook')));
redirect('user/account_linked');
}
}
}
// Load facebook redirect view
$this->load->view("site/redirect_fb");
}
}
connect_create controller
class Connect_create extends Website {
/**
* Constructor
*/
function __construct()
{
parent::__construct();
// Load the necessary stuff...
$this->load->config('account');
$this->load->helper(array('language', 'ssl', 'url'));
$this->load->library(array('authentication', 'form_validation'));
$this->load->model(array('account_model', 'account_details_model', 'account_facebook_model'));
$this->load->language(array('general', 'connect_third_party'));
}
/**
* Complete facebook's authentication process
*
* @access public
* @return void
*/
function index()
{
// Enable SSL?
maintain_ssl($this->config->item("ssl_enabled"));
// Redirect user to home if sign ups are disabled
if ( ! ($this->config->item("sign_up_enabled"))) redirect('tttt');
// Redirect user to home if 'connect_create' session data doesn't exist
if ( ! $this->session->userdata('connect_create')) redirect('bbbbbb');
$data['connect_create'] = $this->session->userdata('connect_create');
// Setup form validation
$this->form_validation->set_error_delimiters('<span class="field_error">', '</span>');
$this->form_validation->set_rules(array(array('field' => 'connect_create_username', 'label' => 'lang:connect_create_username', 'rules' => 'required'), array('field' => 'connect_create_email', 'label' => 'lang:connect_create_email', 'rules' => 'trim|required|valid_email|max_length[160]')));
// Run form validation
if ($this->form_validation->run())
{
// Check if username already exist
if ($this->username_check($this->input->post('connect_create_username', TRUE)) === TRUE)
{
$data['connect_create_username_error'] = lang('connect_create_username_taken');
}
// Check if email already exist
elseif ($this->email_check($this->input->post('connect_create_email'), TRUE) === TRUE)
{
$data['connect_create_email_error'] = lang('connect_create_email_exist');
}
else
{
// Destroy 'connect_create' session data
$this->session->unset_userdata('connect_create');
// Create user
$user_id = $this->account_model->create();
// Add user details
$this->account_details_model->update($user_id, $data['connect_create'][1]);
// Connect third party account to user
switch ($data['connect_create'][0]['provider'])
{
case 'facebook':
$this->account_facebook_model->insert($user_id, $data['connect_create'][0]['provider_id']);
break;
}
// Run sign in routine
$this->authentication->sign_in($user_id);
}
}
$this->load->view('site/connect_create', isset($data) ? $data : NULL);
}
答案 0 :(得分:1)
转到位于 application / config 文件夹中的config.php
设置$config['cookie_domain']="";
试一试。
并尝试在自动加载配置中加载会话库
<强>应用/配置/ autoload.php 强>
$autoload['libraries'] = array('session');