On my web site I would like to have several sub-domains. Files that create context for a given sub-domain are stored in corresponding sub-directory.
Sometimes I need to link to the files that do not belong to the sub-domain.
For example, on my "subdomain1.mysite.org" I have a link to "www.mysite.org/login.php". The "login.php" is stored in the directory that contains all subdirectories corresponding to the sub-domains.
If I make the link to the "www.mysite.org/login.php" in this way: href='../login.php'
, it does not work. Because browser tries to access "subdomain1.mysite.org/../login.php". To solve this problem I make the link in this way: href='http://www.mysite.org/login.php'
but I think that in this way I cannot pass my session variables to the new page (can it be the case?).
So, my problem is that I cannot find a way to pass session variables to the page that is located in the parent directory (or to the page that is located on another domain). Does anybody know how this problem can be solved?
ADDED
As recommended, I tired to use session_set_cookie_params
to solve the problem. But I still cannot manage to get the desired result. In more details I do the following:
I have in the index.php
file that generates 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;
Than later, in the same file I make a link to one of my pages (I think problem can be here). I create the link in the following way:
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 the result there is nothing between "a" and "b". So, I still cannot pass the session variables from one page to another one. Does anybody know what I am doing wrong?
ADDED 2
I have to say that my problem is solved if I add the following line:
session_name("some_name");
before the
session_set_cookie_params
.