Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在所有子域上工作的会话cookie_Php_.htaccess_Session_Cookies_Subdomain - Fatal编程技术网

Php 在所有子域上工作的会话cookie

Php 在所有子域上工作的会话cookie,php,.htaccess,session,cookies,subdomain,Php,.htaccess,Session,Cookies,Subdomain,我的网站设置如下: RewriteCond %{HTTP_HOST} !^www\.example\.com RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC] RewriteRule ^/?$ /user/profile.php?name=%1 [L] 如果用户访问:test.example.com,它将显示文件夹的内容:example.com/user/profile.php?name=test。如果有人进入lol.example.com

我的网站设置如下:

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^/?$ /user/profile.php?name=%1 [L]
如果用户访问:
test.example.com
,它将显示文件夹的内容:
example.com/user/profile.php?name=test
。如果有人进入
lol.example.com
,它将显示页面:
example.com/user/profile.php?name=lol


问题1:

现在,我有一个问题。如果我转到
test.example.com/login
,它将显示我的域根文件。如何使其显示/user文件夹中的内容?例如:
test.example.com/login
将显示
example.com/user/login
test.example.com/register
将显示
example.com/user/register

问题2:已解决

现在,如果我登录子域,会话cookie(PHP)只为子域设置。我如何使cookies在(example.com)域中适用于整个站点

谢谢


更新:例如:
test.example.com/pathtofile
应获取
example.com/user/pathtofile
的内容。“pathtofile”应该是动态的。我只想让路径在文件夹/用户中查找,而不是根文件夹中。

尝试类似的方法

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com [NC]
RewriteRule ^/?$ /user/profile.php?name=%1 [L]
RewriteRule (.*) /user/$1 [L]

不确定htaccess问题,但对于第二个问题,您需要将域设置为*.example.com。[
session\u set\u cookie\u参数(0,“/”,“*.example.com”)
我弄明白了Cookie的事情,必须清除历史记录、缓存、Cookie等等……是不是
$1
?@LFlare你能给我代码吗?不知道你在说什么,谢谢你的回答。但这不仅仅是页面登录和注册。例如:
test.example.com/pathtofile
应该得到
examp>的内容le.com/user/pathtofile
“pathtofile”应该是动态的。我只想让路径在文件夹/user中查找,而不是根文件夹中。@baileyJchoi试试这个。它应该能满足您的所有需要。