Welcome Guest, Not a member yet? Register   Sign In
Work with session
#1

[eluser]indapublic[/eluser]
Little test for sessions:

Code:
<?php

    #    Контроллер основной страницы
    class Mainpage extends Controller
    {        
        function __construct()
        {
            parent::Controller();
        }

        function set()
        {
            $this->session->set_userdata("id", "my_id");
            echo "1: " . $this->session->userdata("id");
        }

        function check()
        {
            echo "2: " . $this->session->userdata("id");
        }

    }

?>

<b>http://mytest/mainpage/set</b> output: 1: my_id
<b>http://mytest/mainpage/check</b> output: 2:

Why?
#2

[eluser]Cristian Gilè[/eluser]
Hi indapublic,

remove any space after ?&gt; or remove the ?&gt; closing tag. Read this
#3

[eluser]indapublic[/eluser]
Thanks for answer. Spaces after ?&gt; is absent. I remove closing tag. But code is not working.
#4

[eluser]Cristian Gilè[/eluser]
Is the above code exactly your controller?

Cristian Gilè
#5

[eluser]ignitian[/eluser]
You need to put the library in your controller.

$this->load->library('session');
#6

[eluser]cideveloper[/eluser]
[quote author="ignitian" date="1294629113"]You need to put the library in your controller.

$this->load->library('session');[/quote]

We have to assume he is auto-loading session otherwise function set would not work.

To indapublic

Are you running check right after set? Are you using DB for sessions? Have you changes any of the Session Preferences?
#7

[eluser]Cristian Gilè[/eluser]
What is the value for $config['sess_expiration'] ?

Cristian Gilè
#8

[eluser]indapublic[/eluser]
[quote author="Cristian Gilè" date="1294609894"]Is the above code exactly your controller?[/quote]
Yes

[quote author="ignitian" date="1294629113"]You need to put the library in your controller.
$this->load->library('session');[/quote]
Library is autoloaded. Otherwise, I will get error during test.

[quote author="Cristian Gilè" date="1294649317"]What is the value for $config['sess_expiration']?[/quote]

Code:
$config['sess_expiration']= 0;

[quote author="progr@mmer" date="1294640038"]
Are you running check right after set? Are you using DB for sessions? Have you changes any of the Session Preferences?[/quote]

1) Yes, right after.
2) No, $config['sess_use_database'] = FALSE;
3) My current config for session:

Code:
$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 0;
$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']     = 7200;

But I changed config to default with same result
#9

[eluser]Atharva[/eluser]
Are you observing this behavior on any specific browser? Have you tested this on all browsers?
#10

[eluser]indapublic[/eluser]
[quote author="Atharva" date="1294657645"]Are you observing this behavior on any specific browser? Have you tested this on all browsers?[/quote]
IE9, Chrome 8.0

+ Opera 11 = same result




Theme © iAndrew 2016 - Forum software by © MyBB