Codeigniter sessions issue in IE9 - codeigniter

Session expiring in IE9 when I have upload any images using ajax call in codeigniter, and I have tried this
1.Writing MY_Session.php file in application/libraries/ but show this error CI_Session not found
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once BASEPATH . '/libraries/Session.php';
class MY_Session extends CI_Session{
function __construct()
{
parent::__construct();
$this->CI->session = $this;
}
function sess_update()
{
// Do NOT update an existing session on AJAX calls.
if (!$this->CI->input->is_ajax_request())
return parent::sess_update();
}
} ?>
/* End of file MY_Session.php */
/* Location: ./application/libraries/MY_Session.php */
config.php :
$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'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

You have to first load CI instance then you are able to load any library
class MY_Session extends CI_Session{
function __construct()
{
$this->ci =&get_instance();
$this->ci->load->library('session');
}
}

Related

Cannot read set userdata session from another controller

I have MY_Controller Extends CI_Controller
I have A Controller Extends MY_Controller and B Controller Extends MY_Controller
When I set session set_userdata in MY_COntroller in can be access in A Controller and also B Controller
But when set session set_userdata in A_Controller it can't be access in MY_Controller and B Controller
But after set session in a controller and print all userdata, the session is exist but not exist in other controller (B & MY COntroller)
IVE set the autoload libraries and also the config
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 1800;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
My COntroller extends CI CONtroller
function __construct()
{
parent::__construct();
$this->readPath();
$this->readApiConfig();
$this->load->library('session');
$this->load->library('user_agent');
}
Login Controller extends My Controller
function __Construct()
{
parent::__Construct();
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->load->helper('captcha');
$this->load->library('session');
$this->load->helper('cookie');
date_default_timezone_set("Asia/Bangkok");
}
function login(){
$email = array(
'usr_email' => $this->input->post("email")
);
$this->session->set_userdata('logged_in', $email);
redirect('landing');
}
Landing Controller extends My COntroller
function __construct()
{
parent::__construct();
$this->load->library('encrypt');
$this->load->library('session');
}
function index() {
//$prod = $this->getExistingAccount();
print_r($this->session->userdata('logged_in'));die();
}
AND ALSO I TRY to ses sess_save_path to APPPATH."CI_SESSION";
and add folder inside application folder name CI_SESSION and set the permission to 0700 but show white blank page
Web url : 192.xxx.x.x : port

Redirection to a controller in sub folder

I cant access to my login controller which is located in the sub directory login.
it is working perfectly in my local server.
in my default controller I did this
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
redirect("login");
}
And in my routes.php
$route['login'] = 'login/log';
Can anyone help me out please?
Try this:
IN YOU CONFIG.PHP
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

Codeigniter & HMVC - Callback not working

I've pretty much gone through a lot of link and solutions provided here and other locations, but I am just not able to solve the callback issue that I am facing. I'm using Codeigniter with HMVC the code is below.
The following code is from My_Form_validation.php:
class MY_Form_validation extends CI_Form_validation {
function run($module = '', $group = ''){
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
Below if the Callback function :
public function _unique_email($str) {
// Check if user already exists
// Process only for current user
$id = $this->uri->segment(4);
$this->db->where('email', $this->input->post('email'));
!$id || $this->db->where('id !=', $id);
$user = $this->mdl_admin_users->get();
if (count($user)) {
$this->form_validation->set_message('_unique_email', 'User already exists. Please check %s.');
return FALSE;
}
return TRUE;
}
and the function :
public function user_edit($id = NULL) {
// Fetch a user or set a new one
if ($id) {
$data['user'] = $this->mdl_admin_users->get($id);
count($data['user']) || $data['errors'][] = 'User could not be found';
}
else {
$data['user'] = $this->mdl_admin_users->get_new();
}
// setup the form
$rules = $this->mdl_admin_users->rules_admin;
$id || $rules['password'] = '|required';
$this->form_validation->set_rules($rules);
//process the form
if ($this->form_validation->run($this) == TRUE) {
$data = $this->mdl_admin_users->array_from_post(array('firstname', 'lastname', 'email', 'password'));
$data['password'] = $this->mdl_admin_users->hash($data['password']);
$this->mdl_admin_users->save($data, $id);
redirect('admin/user');
}
// Load the view
$data['title'] = 'Edit Users';
$data['module'] = 'admin';
$data['header_file'] = 'header_admin';
$data['nav_file'] = 'nav_admin';
$data['view_file'] = 'edit_users';
$data['footer_file'] = 'footer_admin';
echo Modules::run('template/base_template', $data);
}
Would be a great help if someone could point me at the right direction to resolve the issue. Thanks in advance
Naveen
According to wiredesignz,
When using form validation with MX you will need to extend the CI_Form_validation class as shown below,
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
public $CI;
}
before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly.
class Xyz extends MX_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->form_validation->CI =& $this;
}
}
This will remove HMVC related callback problem without any changes to your code.
First of you are missing in the rules
$rules['email'] = 'required|callback__uniqueemail';
Also call back function should be not like this callback__unique_email for some reason I found codeigniter call back not like extra gap this better callback__uniqueemail
If private do not work make public function removing underscore
public function uniqueemail() // no need $str
When make public do not for get to remove extra underscore from here callback_uniqueemail
Another thing with echo Modules run best to be loaded from view only.
In your controller replace echo Modules run with $this->load->view();
You need to add $this->form_validation->run($this) add $this to run after create library below.
And Create a new library
<?php
class MY_Form_validation extends CI_Form_validation {
function run($module = '', $group = '') {
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
Tutorial Best https://www.youtube.com/watch?v=8fy8E_C5_qQ

Query Strings with Code Igniter

I'm trying to setup CodeIgniter (v2.1.4) with Query Strings and having problems with passing variables. The pages work when the controller_trigger and function_trigger are passed:
example.org/?c=page&m=index
But when I try to pass a variable:
example.org/?c=page&m=view&id=1
The script throws 'Missing argument' and 'Undefined variable' errors.
In 'application/config/config.php' I've set:
$config['enable_query_strings'] = TRUE;
In 'application/config/routes.php' I have:
$route['default_controller'] = "page";
And my Controller looks like:
<?php
class Page extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('page_model');
}
public function index()
{
$data['title'] = 'Page Title';
$this->load->view('templates/header', $data);
$this->load->view('page/page_index', $data);
$this->load->view('templates/footer');
}
public function view($id)
{
$data['title'] = 'Id Page Title';
$data['page_item'] = $this->page_model->get_page($id);
$this->load->view('templates/header', $data);
$this->load->view('page/page_view', $data);
$this->load->view('templates/footer');
}
}
Does anyone know what I've missed?
Any help would be greatly appreciated
In your config.php change:
$config['allow_get_array'] = TRUE; #example.com?who=me&what=something&where=here
Write it like this
example.org?c=page&m=index
without "/"

How to pass variables in codeigniter 2

I have following
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hello extends CI_Controller {
var $name = 'test';
function index() {
$this->name = 'Andy';
$data['name'] = $this->name;
$this->load->view('you_view', $data); // THIS WORKS
}
function you() {
$data['name'] = $this->name;
$this->load->view('you_view', $data); // BUT THIS DOESN'T WORK
}
}
My question is how to I pass the $this->name = 'Andy'; to you() ??
Since it is being set in a different method of the controller, which equates to another request in your code, you will need to store it in a session variable to have it persist across page requests.
function index() {
$this->name = 'Andy';
$data['name'] = $this->name;
$this->session->set_userdata('name', $this->name);
$this->load->view('you_view', $data); // THIS WORKS
}
function you() {
$data['name'] = $this->session->userdata('name');
$this->load->view('you_view', $data); // BUT THIS DOESN'T WORK
}
If its a value that is part of the class you can put it in the constructor
class Hello extends CI_Controller {
public function __construct() {
parent::__construct();
// will be available to any method in the class
$this->name = 'andy';
}

Resources