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

Categories

0 votes
504 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 Reply

0 votes
by (71.8m points)

Be sure you set SESSIONID cookie on subdomain, too

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...