我刚刚阅读了这个链接并尝试实现它允许 php 会话转移到子域
在我的本地主机中,我有以下 index.php 文件
<?php
ini_set('session.cookie_domain', '.localhost' );
if ("" === $_POST['login_name']){
}elseif ("" === $_POST['login_password']){
}else{
$_SESSION['login'] = true;
$_SESSION['user'] = $_POST['login_name'];
$_SESSION['group'] = 'support';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Idea Networks And Communications Limited</title>
</head>
<body>
<form action="" method="post" style="display:block;margin:0 auto">
<fieldset>
<legend>Please, Log In</legend>
<label >User Name</label>
<input name="login_name" type="text" maxlength="32" />
<br />
<label>Password</label>
<input name="login_password" type="password" maxlength="32" />
<br />
<input type="submit" value="Log In"/>
</fieldset>
</form>
</body>
</html>
<?php
echo var_dump($_SESSION['login']);
echo var_dump($_SESSION['user']);
echo var_dump($_SESSION['group']);
?>
在 subdomain.localhost 我有以下 index.php 文件
session_start();
echo var_dump($_SESSION['login']);
echo var_dump($_SESSION['user']);
echo var_dump($_SESSION['group']);
但他们打印空值。
谢谢你