I use codeigniter for a project, my session is configured to use the mysql database :
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
In my controller i have a code like this :
$params = array(
"type" => $data['activite_name'],
"activite" => $data['activite'],
"nom" => $data['name'],
"prenom" => $data['fname'],
"tel" => $data['tel'],
"email" => $data['email'],
"adresse" => $data['adr'],
"cp" => $data['cp'],
"ville" => $data['ville']
);
....
#Load session library and save $params as session
$this->load->library('session');
$this->session->set_userdata($params);
#Test session
$sess_name = $this->session->userdata('name');
echo $sess_name;
#Load view
$this->load->view("templates/header_interne", $data);
$this->load->view("pages/payment_view", $data);
$this->load->view("templates/footer", $data);
So when payment_view is loaded i can see my $sess_name value, but when i refresh the page i lost this session, and so on for all my sessions.
Anyone has an idea please?
Thank you.
Related
I am using Codeigniter 3.1.9, and added items to my shopping cart, items are added and showing but when i put my system to hibernate mode with browser open, then after turning on my sytem, the cart shows 0 products. It should contain the item that i have added. Please help to sort out my issue.
My add to cart code snippet is:
$data = array(
'id' => $product['id'],
'qty' => 1,
'size' => $size,
'name' => $product['title'],
'image' => $product['image']
);
$this->cart->insert($data);
this is config file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Codeigniter cart library save data in session. after hibernate, the session got destroy and your cart got cleared.
I am trying to start the session with CodeIgniter, but it does not show any error either. I tried to change the session's driver to database and also I tried to specify the session path, but I didn't work.
$session_data = array(
'is_login' => TRUE,
'username' => $user->username,
'id' => $user->id,
'type' => $user->type,
'name' => $user->name,
);
$this->session->set_userdata($session_data);
From Comment
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
First open the file located at application/config/autoload.php
Find the following section.
The $autoload['libraries'] = array(); array holds the list of libraries that need to be autoloaded.
As per our requirement, let's change it to look like this:
$autoload['libraries'] = array('session');
Also, there's another way you could have achieved that. You can use the following code somewhere in your controller file to load the session library.
$this->load->library('session');
i am using drupal_validate_form on a node listing page .
it is validating it correctly only for 1st item after that it is not checking validation.
here is my code
foreach($result as $r){
$node_form = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#submit'] = array('#type' => 'submit', '#value' => t('Next'));
$old_fs = #unserialize($r->form_state);
$old_fs['values']['uid'] = $user->uid;
$node = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
node_object_prepare($node);
$form_state = array();
$form_state['build_info']['args'] = array($node);
$form_state['values'] = $old_fs['values'];
$form_state['values']['op'] = t('Save');
$form_state['submitted'] = 1;
$form_state['complete form'] = array();
$form_state['triggering_element'] = array('#parents'=>array('next'),'#button_type'=>'submit');
unset($form['#token']);
drupal_validate_form('MY_CONTENT_TYPE_node_form', $form, $form_state);
$errors = form_get_errors();
$noOfError = 'empty';
if (!empty($errors)) {
$noOfError = count($errors);
}
form_clear_error();
}
thank You in advance
Finally i have to reset need_validation in $form .
Because every time form get for validation it will chack $form['#needs_validation'] in _form_validate();
so i added another line after
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#needs_validation'] = TRUE;
and it will validate every form in that loop
I am at my wits end and don't know why my code is not working . Everything seems good to me .. I have implemented a captcha in my user review function and added a verification method using callback_ .
The captcha is showing in the view and i have dumped the session data and the input field data and they are both working.
The form validation is also working in case of captcha input field but seems like the callback_check_captcha parameter is not working but the function seems fine to me .
Here is my controller
function user_review($id = null , $start = 0){
$check_id = $this->mdl_phone->get_phone_feature($id);
if ($check_id == null ) {
$data['phone_model'] = $this->get_phone_models();
$data['feature'] = null;
$data['title'] = 'Nothing Found';
$data['main_content']= 'phone/error';
echo Modules::run('templates/main',$data);
} else{
$data['phone_model'] = $this->get_phone_models();
$data['success'] = null;
$data['errors'] = null;
if($this->input->server("REQUEST_METHOD") === 'POST' ){
$this->load->library('form_validation');
$this->form_validation->set_rules('text','Review','required|xss_clean');
$this->form_validation->set_rules('captcha', 'Captcha','trim|required|callback_check_captcha');
if($this->form_validation->run() == FALSE){
$data['errors'] = validation_errors();
}else{
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$data = array(
'phone_id' => $id,
'user_id' => $user_id,
'text' => strip_tags($this->input->post('text')),
);
$this->db->insert('user_review' ,$data);
$data['phone_model'] = $this->get_phone_models();
$data['success'] = 'Your Review has been successfully posted ';
$data['errors']= null;
}
}
// Initilize all Data at once by $id
$data['feature'] = $this->mdl_phone->get_phone_feature($id);
//$data['rating'] = $this->mdl_phone->get_user_rating($id);
$data['user_review'] = $this->mdl_phone->get_user_review($id , 5 , $start);
$this->load->library('pagination');
$config['base_url'] = base_url().'phone/user_review/'.$id;
$config['total_rows'] = $this->mdl_phone->get_user_review_count($id);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$config['anchor_class'] = 'class="page" ';
$this->pagination->initialize($config);
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'img_width' => 150,
'img_height' => 30,
);
$cap = create_captcha($vals);
$this->session->set_userdata('captcha',$cap['word']);
$data['captcha'] = $cap['image'];
$data['title'] = $this->mdl_phone->get_phone_title($id)." User Review , Rating and Popularity";
$data['main_content'] = 'phone/user_review';
echo Modules::run('templates/main',$data);
}
}
function check_captcha($cap)
{
if($this->session->userdata('captcha') == $cap )
{
return true;
}
else{
$this->form_validation->set_message('check_captcha', 'Security number does not match.');
return false;
}
}
The bellow CAPTHA working properly refer this code
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . '/captcha/'
);
$cap = create_captcha($vals);
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$this->session->set_userdata($data);
$data['cap_img'] = $cap['image'];
I think your image url problem or you are not giving a file permission to the captha folder .
I'm having database connection issues.
Here is the error I get:
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
Here is my database.php file settings:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user';
$db['default']['password'] = 'password';
$db['default']['database'] = 'dvp';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I've placed this code at the bottom of my database.php file:
echo '<pre>';
print_r($db['default']);
echo '</pre>';
echo 'Trying to connect to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']);
echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . '--> Line: ' .__LINE__);
And the following info displays:
Array
(
[hostname] => localhost
[username] => user
[password] => password
[database] => dvp
[dbdriver] => mysql
[dbprefix] =>
[pconnect] => 1
[db_debug] => 1
[cache_on] =>
[cachedir] =>
[char_set] => utf8
[dbcollat] => utf8_general_ci
[swap_pre] =>
[autoinit] => 1
[stricton] =>
)
Trying to connect to database: dvp
Connected OK
Any ideas?
Ug, found the issue. Someone manually added a second set of db settings in another file and was calling them in from there. What a mess!