On my website, I would like to have several subdomains. Files that create the context for this subdomain are stored in the appropriate subdirectory.
Sometimes I need to refer to files that do not belong to a subdomain.
For example, on my "subdomain1.mysite.org" I have a link to "www.mysite.org/login.php". "Login.php" is stored in a directory that contains all the subdirectories corresponding to the subdomains.
If I make a link to "www.mysite.org/login.php" this way: href='../login.php' , this will not work. Because the browser is trying to access "subdomain1.mysite.org/../login.php". To solve this problem, I make the link as follows: href='http://www.mysite.org/login.php' , but I think that in this way I can not transfer my session variables to a new page (maybe so ?).
So my problem is that I cannot find a way to pass the session variables to a page located in the parent directory (or on a page located in another domain). Does anyone know how this problem can be solved?
ADDED
As recommended, I'm tired of using session_set_cookie_params to solve the problem. But I still canβt get the desired result. In more detail I do the following:
In the index.php file that generates the content for subdomain1.mysite.org , I use the following code:
session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); $_SESSION['page'] = $PHP_SELF;
The later, in the same file, I will make a link to one of my pages (I think the problem may be here). I create the link as follows:
href='http://www.mysite.org/login.php'
In the login.php file, I have the following code:
session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); print "a".$_SESSION['page']."b";
As a result, there is nothing between "a" and "b". Thus, I still cannot transfer session variables from one page to another. Does anyone know what I'm doing wrong?
ADDED 2 I have to say that my problem is resolved if I add the following line: session_name("some_name");
before
session_set_cookie_params .