错误session_start():无法发送会话cookie - 已在我的codeigniter中发送的标头

时间:2015-11-08 05:06:29

标签: php codeigniter cookies

enter image description here

我正在开发codeiniter我将我的文件上传到服务器,但它给了我这个错误。相同的代码在localhost上正确运行。所以我的代码有什么不对。

这是控制器

    <?php

class Login extends CI_Controller {

    function Index()
    {
        $data['Main_content'] = 'Login_form';
            //$this->load->view('header2');
        $this->load->view('Includes/Template', $data);  
        //$this->load->view('footer');  
    }

    function Validate_credentials()
    {       
        $this->load->model('Membership_model');
        $query = $this->Membership_model->Validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'Is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('Site/Members_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }   

    function Signup()
    {
        $data['Main_content'] = 'Signup_form';
        $this->load->view('Includes/Template', $data);
    }

    function Create_member()
    {
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');


        if($this->form_validation->run() == FALSE)
        {

            $data['Main_content'] = 'Signup_form';
            $this->load->view('Includes/Template', $data);




        }

        else
        {           
            $this->load->model('Membership_model');

            if($query = $this->Membership_model->Create_member())
            {
                $data['Main_content'] = 'Signup_successful';
                $this->load->view('Includes/Template', $data);
            }
            else
            {
                $this->load->view('Signup_form');           
            }
        }

    }

    function Logout()
    {
        $this->session->sess_destroy();
        $this->Index();
    }

}

这是网站控制器

<?php

class Site extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
        $this->Is_logged_in();

    }

    // function status()
    // {
    //  $this->load->model("Emp_model");
    //  $data['showEmployeeTable']=$this->Emp_model->selectEmployeeData5();

    //      $this->load->view('header',$data);
    //  $this->load->view('dashboard');
    //  $this->load->view('footer');


    // }

    function Members_area()
    {
        //$this->load->view('logged_in_area');


            $this->load->view('Header');
        $this->load->view('Dashboard');
        $this->load->view('Footer');

    }

    function Another_page() // just for sample
    {
        echo 'good. you\'re logged in.';
    }

    function Is_logged_in()
    {
        $Is_logged_in = $this->session->userdata('Is_logged_in');
        if(!isset($Is_logged_in) || $Is_logged_in != true)
        {


            echo 'You don\'t have permission to access this page. <a href="../login">Login</a>';    
            die();  

            //$this->load->view('login_form');
        }       
    }   

}

这是模型

class Membership_model extends CI_Model {

    function Validate()
    {
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $query = $this->db->get('membership');

        if($query->num_rows() == 1)
        {
            return true;
        }

    }

    function Create_member()
    {

        $new_member_insert_data = array(
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'),
            'email_address' => $this->input->post('email_address'),         
            'username' => $this->input->post('username'),
            'password' => md5($this->input->post('password'))                       
        );

        $insert = $this->db->insert('membership', $new_member_insert_data);
        return $insert;
    }
}

这是VIWE

<!DOCTYPE html>

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Sign Up!</title>
    <link rel="stylesheet" href="<?php echo base_url();?>css/style2.css" type="text/css" media="screen" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8">

</script>

</head>
<body>
<?php $this->load->view('Includes/Header'); ?>

<div id="main_content">

<?php $this->load->view($Main_content); ?>

</div>

<?php //$this->load->view('includes/tut_info'); ?>

<?php $this->load->view('Includes/Footer'); ?>

    <script type="text/javascript" charset="utf-8">
    $('input').click(function(){
        $(this).select();   
    });
</script>

1 个答案:

答案 0 :(得分:1)

我想你的控制器可能有空白区域。去掉它。并尝试一下