html - Sharing session data across domains with PHP


My user is logged in on a CMS, however I am now developing a mobile version of the site, outside the CMS on a and would like the session to be carried over.

I have included a file with all the CMS' functions like this:

<?php include_once'/home/flyeurov/public_html/core/codon.config.php';?>

I can login fine on the mobile site:

<input type="hidden" name="mobileVersion" value="True">
<input type="hidden" name="redir" value="" />
<input type="hidden" name="action" value="login" />
<input class="login-btn" type="submit" name="submit" value="Log In" />

The above is processed bylogin.php. However, CMS login redirects it to CMS' page, and I need the mobile version to redirect to a page in /mobile directory subdomain points. Hence, inlogin.php (not to be confused withmobile/login.php - mainlogin.php is for the CMS). I did this, and it redirects tomobile/crew_center.php - a page it should redirect to on a mobile version.

if (isset($_POST['mobileVersion'])) {
            } else {
                $this->post->redir = str_replace('index.php/', '', $this->post->redir);
                header('Location: '.url('/'.$this->post->redir));

Maybe the above code has something to do with my problem.

My problem is that the session from the main CMS is not carried over to the mobile site. Inmobile/index.php I have this statement, which does not work. When logged in, the user should seecrew_center.php as it would be pointless to display the login form. At the moment, when the user is logged in on the CMS, the login page still appears on the mobile version.

However, if I drop the subdomain in the browser and typesite_url/mobile it will open the right pagecrew_center.php.

<?php include_once'/home/flyeurov/public_html/core/codon.config.php';

session_set_cookie_params(0, '/', '');

    header("Location: crew_center.php");
    header("Location: login.php");


How can I fix this, and how can I share session data from a main domain to a subdomain with the use of PHP?

codon.config.php -




You need to set the cookie's domain accordingly - add a. to your domain name:

session_set_cookie_params(0, '/', '');

This will share your cookie across all of your sub domains and the second level domain.

People are also looking for solutions to the problem: Using PHP to output MySQL query as SQLite


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.