简体   繁体   中英

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'];
?>

确保你也在子域上设置了 SESSIONID cookie

ini_set('session.cookie_domain', '.my-domain.com');

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...
?>

默认情况下,这不起作用,但您可以按照此处所述解决它: http : //www.gonnalearn.com/2008/04/10/sharing-session-data-across-domains-with-php/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM