PHP: SESSION lost on SUBDOMAIN

*爱你&永不变心* 提交于 2019-12-28 03:11:04

问题


I am trying to use session data on multiple subdomains. Ej:

  • www.mywebsite.com
  • my.mywebsite.com
  • test.mywebsite.com
  • whateversub.mywebsite.com

When I try to use session data from www.mywebsite.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.mywebsite/index.php

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

File 2:

<?php
//FILE 2: sub.mywebsite/index.php

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

回答1:


Be sure you set SESSIONID cookie on subdomain, too

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



回答2:


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



回答3:


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/



来源:https://stackoverflow.com/questions/7324822/php-session-lost-on-subdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!