提交表单时会话数据很多

时间:2019-01-09 11:49:35

标签: php mysql codeigniter

我有一种将记录添加到MySQL数据库的方法。该应用程序在CodeIgnite中进行了编程。我使用以下代码获取当前登录用户的ID-

$agentId = $this->session->userdata('agentid');

当我在表单页面顶部回显$ agentId时,它显示28是正确的。单击“保存”按钮并运行该方法后,会话将清除它并注销用户。我不知道为什么会这样。

public function add(){
    $agentId = $this->session->userdata('agentId');     
    echo $agentId;      
    if(!$agentId){
        redirect(base_url().'login', 'refresh');    
    }
    if(!isSuperAdmin() && !isPayment()){
        redirect(base_url().'payment', 'refresh');
    }

    $data['p_title'] = $this->project_model->projectName().' :: Property : Add New Property';
    $data['Message'] = '';  
    $data['heading'] = 'Property: Add New Property';
    $data['pageName'] = 'property';

    $data['title'] = filter_value('title', '');
    $data['meta_decription'] = filter_value('meta_decription', '');
    $data['keywords'] = filter_value('keywords', '');
    $data['type'] = filter_value('type', '');
    $data['sub_type'] = filter_value('sub_type', '');
    $data['sub_type1'] = filter_value('sub_type1', '');
    $data['bedrooms'] = filter_value('bedrooms', '');
    $data['kitchen'] = filter_value('kitchen', '');
    $data['parking'] = filter_value('parking', 'YES');
    $data['bathrooms'] = filter_value('bathrooms', '');
    $data['price'] = filter_value('price', '0.00');
    $data['rent_frequency'] = filter_value('rent_frequency', '');
    $data['deposit'] = filter_value('deposit', '0.00');
    $data['location'] = filter_value('location', '');
    $data['city'] = filter_value('city', 82);
    $data['country'] = filter_value('country', 102);
    $data['details'] = filter_value('details', '');
    $data['featured'] = filter_value('featured', 'NO');

    $data['countries'] = $this->general_model->listCountries($data['country']);
    $data['cities'] = $this->general_model->listCities($data['country'], $data['city']);

    $this->form_validation->set_rules('title', 'Property title', 'trim|required');
    if($this->form_validation->run() === TRUE){
        // the agentId variable is lost here, so 0 gets etntered in to the database and the user is logged out.         
        $agentId = $this->session->userdata('agentId');
        $Date = getCurrentDate();
        $Time = getCurrentTime();
        $DbFieldsAry = array('agentId', 'title', 'meta_decription', 'keywords', 'type', 'sub_type', 'sub_type1', 'bedrooms', 'kitchen', 'parking', 'bathrooms', 'price', 'rent_frequency', 'deposit', 'location', 'city', 'country', 'details', 'featured', 'date');
        $InfoAry = array($agentId, $data['title'], $data['meta_decription'], $data['keywords'], $data['type'], $data['sub_type'], $data['sub_type1'], $data['bedrooms'], $data['kitchen'], $data['parking'], $data['bathrooms'], $data['price'], $data['rent_frequency'], $data['deposit'], $data['location'], $data['city'], $data['country'], $data['details'], $data['featured'], $Date);                

        if($this->general_model->duplicateEntry($DbFieldsAry, $InfoAry, 'tbl_properties_list')){                    
            $activityId = $this->general_model->getSingleValue($data['title'], 'title', 'property_id', 'tbl_properties_list');
            setMessage('success_message', 'New property added successfully. Add pictures to property.');
            redirect(base_url().'property/update/'.$activityId.'/0', 'refresh');
        }
        else{
            setMessage('error_message', 'Unable to perofrm this operation, please try again later!');
            redirect(base_url().'property/user_listing', 'refresh');    
        }

    }

    $data['allowed'] = true;
    $data['warning'] = '';

    if(!isSuperAdmin()){
        $total_properties = $this->general_model->getTotalDataSimple1('property_id','tbl_properties_list');
        if(allowed_properties() <= $total_properties){
            $data['allowed'] = false;
            $data['warning'] = '<br/>You have reached to maximum limit of your property upload listing.<br/>Click <a href="'.base_url().'payment">HERE</a> to change payment plan.<br/><br/><br/><br/><br/>';
        }
    }
    $this->load->view('add_property', $data);

}

这是config.php中的会话

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 14400;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 600;

1 个答案:

答案 0 :(得分:0)

我假设您已经在构造函数或自动加载文件中加载了会话库。如果没有,那也许就是问题所在。如果可以,则尝试在codeigniter的config.php中更改会话超时或会话存储方法。