Reputation: 12297
I am trying to use session data on multiple subdomains:
When I try to use session data from www.example.com to any subdomain, all the session information is not accessible.
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'];
?>
Upvotes: 3
Views: 16777
Reputation: 12297
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...
?>
Upvotes: 7
Reputation: 50976
Be sure you set SESSIONID cookie on subdomain, too
ini_set('session.cookie_domain', '.my-domain.com');
Upvotes: 7
Reputation:
By default this will not work, but you can get around it as described here: http://www.gonnalearn.com/2008/04/10/sharing-session-data-across-domains-with-php/
Upvotes: 1