Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

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'];
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Be sure you set SESSIONID cookie on subdomain, too

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...