Search code examples
phpsessionsubdomain

PHP: SESSION lost on SUBDOMAIN


I am trying to use session data on multiple subdomains:

  • www.example.com
  • my.example.com
  • test.example.com
  • whateversub.example.com

When I try to use session data from www.example.com to any subdomain, all the session information is not accessible.

  • I am NOT using cookies. Just sessions.
  • I have GoDaddy as web host.
  • GoDaddy DOES allow to upload a custom php5.ini file.

Since I am a PHP beginner, please dumb down your response so I may understand it.

Here is an example:

File 1:

<?php
// FILE 1: www.example.com/index.php

session_start();
$_SESSION['status'] = "ON";
header( 'Location: http://sub.mywebsite/' );
?>

File 2:

<?php
// FILE 2: sub.example.com/index.php

session_start();
echo "Your session status is: ";
echo $_SESSION['status'];
?>

Solution

  • I solve my problem thanks to this link PHP Sessions across sub domains

    PHP:

    <?php
    session_set_cookie_params(0, '/', '.mywebsite.com');
    session_start();
    //Code...
    ?>