onclick pagination link, session expired in codeigniter

IN Controller,

    public function index($offset = 0)
    {   
        $state= $this->input->post('state');
        $city= $this->input->post('city');
        $data = array(
                'state' => $state,
                'cities' => $city
            );
        $this->session->set_userdata($data);
        $data['active']='Search';

        $this->load->library('pagination');
        $config['base_url']= site_url()."search/index/";
        $config['total_rows']= 100;
        $config['per_page'] = 5;
        $config['num_links'] = 4;
        $config['uri_segment'] = 3;
        $config['full_tag_open'] = '<div class="pagination"><ul class="pagination">';
        $config['full_tag_close'] = '</ul></div>';


        $this->pagination->initialize($config);

        $result = $this->mymodel->search($city,$state,$offset);

        $data['pagination'] = $this->pagination->create_links();

        $data['search_result']=$this->build_result_html();
        $this->load->view('search',$data);
    }

In view Pagination displaying properly but, on click of pagination link then session always expired please help me Thanks.

Answers


You can use get instead of post to fetch data. I tat way iu dont need to create a session for it.

Your controller becomes some thing like this.

public function index($offset = 0)
    {   
        $state= $this->input->get('state');
        $city= $this->input->get('city');

        $this->load->library('pagination');
        $config['base_url']= site_url()."search/index/";
        $config['total_rows']= 100;
        $config['per_page'] = 5;
        $config['num_links'] = 4;
        $config['uri_segment'] = 3;
        $config['full_tag_open'] = '<div class="pagination"><ul class="pagination">';
        $config['full_tag_close'] = '</ul></div>';


        $this->pagination->initialize($config);

        $result = $this->mymodel->search($city,$state,$offset);

        $data['pagination'] = $this->pagination->create_links();

        $data['search_result']=$this->build_result_html();
        $this->load->view('search',$data);
    }

I your search for u need to add a attribute to form method="get"


try this

  $state= $this->input->post('state');
  $city= $this->input->post('city');
if(!empty($city) && !empty($state) ){
        $this->session->set_userdata('state',$state);
         $this->session->set_userdata('cities',$city);
    }

i try on my local

$state= 'asdasd';
     $city= 'asdasd';
    if(!empty($city) && !empty($state) ){   // if its having value then set session
            $this->session->set_userdata('state',$state);
             $this->session->set_userdata('cities',$city);
        }
        print_r($this->session->userdata);

output is

Array ( [session_id] => 2c717eb44e99fb1def09af56250aa5bc [ip_address] => 127.0.0.1 [user_agent] => Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36 [last_activity] => 1396079813 [user_data] => [id] => 2 [name] => [state] => sadfasd [cities] => fddsfdf )

with no value

 $state= '';
         $city= '';
        if(!empty($city) && !empty($state) ){   // if its having no value then still value of session is same 
                $this->session->set_userdata('state',$state);
                 $this->session->set_userdata('cities',$city);
            }
            print_r($this->session->userdata);

output is

Array ( [session_id] => 2c717eb44e99fb1def09af56250aa5bc [ip_address] => 127.0.0.1 [user_agent] => Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36 [last_activity] => 1396079813 [user_data] => [id] => 2 [name] => [state] => sadfasd [cities] => fddsfdf )

Need Your Help

Injecting Logger in Symfony 2 ODM Documents

symfony logging dependency-injection doctrine-odm symfony-2.7

I am currently developing a Symfony 2 Application and I want to log when some setters are called in my Models.

Making Class thread safe

java android multithreading thread-safety

This code is generated for saving event history in my app as I need to provide some code as :