CodeIgniter Forums

Full Version: Get data from cookie on subdomain with Codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I already checked couple threads here but I was not able fix my problem.

I have 2 apps:
  • 1st app is pure php ecommerce website on domain www.mydomain.com, where I did initialization with:
Code:
session_set_cookie_params( $currentCookieParams["lifetime"], $currentCookieParams["path"], $rootDomain, // $rootDomain = ".mydomain.com" $currentCookieParams["secure"], $currentCookieParams["httponly"] );
  • 2nd app uses Codeigniter on domain sub.mydomain.com and is configured like this:
Code:
$config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'cookie_name'; $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['cookie_prefix'] = ''; $config['cookie_domain'] = '.mydomain.com'; $config['cookie_path'] = '/'; $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE;
I will add an item to cart on www.mydomain.com. Data are stored in cookies under
Code:
cookie_name
. Then I open sub.mydomain.com to check if data are shared. In chrome dev tools under Application/Cookies I can see that value of
Code:
cookie_name
is same on both domains.
Problem is I am not able to get this data on subdomain with Codeigniter (using
Code:
$_SESSION
or
Code:
$this->session->userdata();
). It returns array with only item
Code:
[__ci_last_regenerate]
.
I created sample file on sub.mydomain.com/test.php where I am able to get data from session using php without codeigniter => so data are available there...But I need to get them with Codeigniter. Any ideas?
If you can get the data with native PHP, then there is no reason not to do it that way.

CodeIgniter does not force you to do it via only CI available methods.
(07-12-2017, 01:19 AM)Martin7483 Wrote: [ -> ]If you can get the data with native PHP, then there is no reason not to do it that way.

CodeIgniter does not force you to do it via only CI available methods.

Native PHP can be used in CI and assign data to variable?

How to?
I don't understand you response. You said this

Quote:I created sample file on sub.mydomain.com/test.php where I am able to get data from session using php without codeigniter => so data are available there...But I need to get them with Codeigniter. Any ideas?

So if you could read the data with the sample file on your subdomain with native PHP, how is it you don't know how to assign it to a variable?
instead of using $this->session->userdata(); just use the $_SESSION global