0

Suppose the domain I am working on is www.example.com and it has a link shop which takes the user to subdomain shop.example.com

Now on shop.example.com when user add product to cart the the cart information is stored in $_SESSION['prd'] variable.

This session variable is available and count of cart items is perfectly displayed in shop.example.com but problem arises when i go to example.com then this session variable is not there.

I tried adding below line at the end of .htaccess

php_value session.cookie_domain ".example.com"  

but this gives 500 error.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Gags
  • 3,759
  • 8
  • 49
  • 96
  • possible duplicate of [Preserving session variables across different domains](http://stackoverflow.com/questions/14611545/preserving-session-variables-across-different-domains) – Saty May 22 '15 at 09:30
  • @saty This should be a lot easier since `shop.example.com` and `www.example.com` are on the same domain, and on the same server. – Sumurai8 May 22 '15 at 09:32
  • @Gags Go to your Apache error log and read what error it gives you. Internal server errors always log something that lets you figure out how to solve it. – Sumurai8 May 22 '15 at 09:34
  • how to access it on cpanel? – Gags May 22 '15 at 09:52

2 Answers2

1

As simple as it may seem did you try removing the quotes from around your subdomain?

php_value session.cookie_domain .example.com

I've not got the complete solution working yet, but this at least doesn't give any errors.

DigiDamsel
  • 106
  • 6
0

I had a similar problem, however, this solution was good for me, perhaps will help others in the future

edit you php.ini

session.cookie_domain = ".exemple.com"

or in you script php

session_set_cookie_params(0, '/', '.example.com');

session_start();

if you have problems try add this in your php.ini

suhosin.session.cryptdocroot = Off

suhosin.cookie.cryptdocroot = Off