index.php
session_start();
if(!isset($_GET['n'])) {
$_SESSION['foo'] = "bar";
header("Location: /index.php?n=D");
}
echo "FOO: ".$_SESSION['foo'];
This page index.php
is used in a subdomain. The subdomain is a folder in the root domain, i.e.
- WWW
- SUB DOMAIN
- index.php
The session variable foo
is set on page call, then checked after a redirect header - and it's gone.
I've tried:
ini_set('session.cookie_domain','.example.com');
- Various combinations of
session_set_cookie_params()
- Location: http://subdomain.example.com
- Tearing my hair out
but nothing seems to be working. Seems like a very simple problem - can someone help me find my lost cookie / session / variable ?
EDIT
var_dump(session_get_cookie_params())
yields
array(5) { ["lifetime"]=> int(0) ["path"]=> string(11) "/" ["domain"]=>
string(23) ".example.com" ["secure"]=> bool(false) ["httponly"]=> bool(false) }
My URL has a dash -
in it (my-example.com). Could this be the problem?
Also tried setting session_name()
before params. Still not working.