php - session is not working in new server

562

I moved my code-igniter project to new server but session is not working across other page but in same page controller function is like

public function login()
{
    $typo = "teacher";
    $co=array('ededge_typo' => $typo);
    $this->session->set_userdata($co);
    $this->load->view('header');
}

in view

<?php var_dump($this->session->userdata('ededge_typo'))); ?>

but i get output Null

when i tried in localhost i get

C:\wamp\www\cii\application\views\header.php:1:string 'Teacher' (length=7)

please help me to

my configuration in codeigniter is

$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;
$config['time_reference'] = 'gmt';
971

Answer

Solution:

Have you tried to print session by print_r($_SESSION) on your view page. Print it, if your session is set it will show you.

380

Answer

Solution:

Use database session

https://codeigniter.com/userguide3/libraries/sessions.html

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Thanks.

445

Answer

Solution:

$config['sess_driver'] = 'files';
$config['sess_save_path'] = '/var/www/html/my_app/tmp/';

From codeigniter documentation:

'sess_save_path' | | The location to save sessions to, driver dependent. | | For the 'files' driver, it's a path to a writable directory. | WARNING: Only absolute paths are supported! | | For the 'database' driver, it's a table name. | Please read up the manual for the format with other session drivers. | | IMPORTANT: You are REQUIRED to set a valid save path!

If you dont want to change that folder manually every time when you change server, you could try something like

$config['sess_save_path'] = FCPATH . 'tmp/';
$config['sess_save_path'] = BASEPATH . 'tmp/';

The fcpath one should be xxx/my_app/tmp and basepath should be xxx/my_app/application/tmp

Both folders should be writeable.

People are also looking for solutions to the problem: javascript - Populate second input text based on previous one

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.