gpt4 book ai didi

php - 提交表单时 session 数据会变得很多

转载 作者:行者123 更新时间:2023-11-29 16:28:15 26 4
gpt4 key购买 nike

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

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

当我将 $agentId 回显到表单页面顶部时,它显示 28,这是正确的。单击“保存”按钮并运行该方法时, session 会清除它并注销用户。我不明白为什么会发生这种情况。

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 中的 session

$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;

最佳答案

我假设您已经在构造函数或自动加载文件中加载了 session 库。如果不是,那就可能是问题所在。如果是,请尝试更改 codeigniter 的 config.php 中的 session 超时或 session 存储方法。

关于php - 提交表单时 session 数据会变得很多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54109458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com