views:

140

answers:

6

Hi , i'm trying to use native $_SESSION arrays in Codeigniter beacause i can't use $_COOKIES arrays, so i made my own class but seems that Codeigniter continue to save data on cokkies cause if i disable browser cookies i can't retrieve $_SESSION data :O !! incredible....i can't understand why? is codeigniter stopping or removing all $_SESSION data setted ?

is there someone that is still using only $_SESSION arrays ,aborting default $_COOKIE arrays option? i mean ,i would like to have session data not cookie data but it seems to be impossible :O!!!??!!

thanks to who will answer ;)

A: 

There's a cookie that stores PHPSESSID browser side.

chigley
thanks and if i want to take out this option? :)
memento
sorry does it means that i can't retrieve $_SESSION i setted?
memento
need i to try setting other session id? :P
memento
+2  A: 

Yes you can do that

create this table:

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id)
);

and change this in the config:

$config['sess_use_database'] = FALSE;

to

$config['sess_use_database'] = TRUE;

$config['sess_table_name'] = 'ci_sessions'; should match the name of your table.

To clarify - by default, CI's session system uses a cookie to store the data. Don't know why, it just does. You can change this for security etc by using the database table instead.

You access session values exactly the same, but aren't restricted by cookie maximum file sizes, or security risks.

You can of course use normal $_SESSIONS and create your own script - remember CI is a framework, you aren't required to use all of it.

Ross
so i have to use database :O??? ufff :(
memento
there's no option to return $_SESSION arrays??? or to stop blocking them? :)
memento
show us some sample code
Ross
oks i'll use a bigger post :) let me 1 min :P i will post all code
memento
This just stores session data, nothing to do with SID Tracking, Its purely down to cookies or `GET` Parameters, this is just a different driver for storing session data.
RobertPitt
This method still stores a cookie client side...
chigley
so there's no way to use personal $_SESSION array? :O
memento
+5  A: 

$_SESSION variables may not be in the cookies themselves, but PHP still needs to be able to track the user's session in order for the $_SESSION variables to be persistent, and it uses cookies for that tracking.

PHP does try to maintain session state if cookies are turned off, by passing the session variable in the URL, but it isn't very reliable.

Bottom line - if you want session data in a web environment, you'll need cookies turned on. Sorry.

You say you can't use cookies, but you didn't really explain why. It's fairly unusual these days for people to want to turn off cookies, as they're used virtually everywhere.

Spudley
sorry $_SESSION are not cookies i mean :P , i should can retrieve $_SESSION if cookies are turned off don't you think?
memento
i can't use cookie for project establishment
memento
It's very simple: sessions are managed via cookies or via a URL parameter. If you have cookies turned off, you must include the session URL paramter on every page load, otherwise you won't be able to retrieve session data. See the PHP manual page on sessions to confirm this: http://www.php.net/manual/en/intro.session.php
Spudley
yes , now i'm trying to take back $_SESSION data with a normal php scripts out of the framework, but i still can't retrieve $_SESSION when cookies are disabled :/ , i think this is a php.ini problem ,don't you think?
memento
A: 

Since when does CodeIgniter "block" $_SESSION? If you want to use a session, you have to start it. To do that you need to write session_start() somewhere. why not in your index.php?

CodeIgniter is just PHP, not some evil dark magician.

Phil Sturgeon
yes i have write session_start at beginning of 1)personal library as you can see, i think CI starts this option when loading library , or does is not true? :P
memento
have you ever used $_SESSION into codeigniter?
memento
Sorry your code was badly formatted and I missed it. Why are you creating a library for this? If you want to work with $_SESSION then just do it, and modify as usual. I have worked with $_SESSION several times using this exact method.
Phil Sturgeon
A: 

i have renamed CI original Session.php library as Cookie.php,and than i made two personal classes into application/libraries and i load them by default into autoloader.php

1) Personal Library - Session.php

session_start();

class Session {

 function set_data($key,$data)
{

  if(!$key)
  { echo 'first param passed is null in session set_data';}
  if(!$data)
  { echo 'second param passed is null in session set_data';}
 if(isset($key) && isset($data))
 {
     if(isset($_SESSION[$key]))
     {
         unset($_SESSION[$key]);
     }

  return $_SESSION[$key] = $data;


 }

function keep_data($key) {

   if(!$key)
  { echo 'first param passed is null in session keep_data';}

   if(isset($_SESSION[$key]))
   {
     return htmlentities($_SESSION[$key]);
   }

}

2) Personal Library - Settings.php

class Settings {

 function setsitelanguage()
{
    $CI =& get_instance();

    if($CI->session->keep_data('lang'))
    {
        $CI->config->config['language'] = $CI->session->keep_data('lang');
    }
    else
    {
      $CI->config->config['language'] = "en";
    }

}

than i have 2 controllers


1) Controller Home.php

class Home extends Controller {

function Home()
{

    parent::Controller();

           $this->settings->setsitelanguage();

    }


function index()
{
    $this->load->view('home/home_view');

}
    function session()
    {
       echo   $this->session->keep_data('lang');
    }

}

2) Controller Auth.php

class Auth extends Controller {

 function usersetlang()
{

           $lang = $this->uri->segment(3);

          return $this->session->set_data('lang',$lang);





    }

}

as shown in http://mysite/index.php/home/session, i can retrieve my language site stored with session.php by auth.php the only problem is that is not enough using global $_SESSION[] ,because if i try to retrieve data disabling my browser cookies $_SESSION[] data doesn’t appears !!!

memento
Momento, Please append to your own post, did you not read the dialogue that popped up when you clicked **Post an answer**
RobertPitt
ehm....pardon :P
memento
A: 

If you can't propagate the session id via cookies, you can do so via URL.

See: http://www.php.net/manual/en/session.idpassing.php

kemp