简体   繁体   English

在php中的同一个域上有1个会话(id)

[英]1 session (id) on the same domain in php

I'm running PHP7 on a debian 8 server. 我在debian 8服务器上运行PHP7。 I host 2 domains on this server. 我在这台服务器上托管了2个域名。 What I want is 1 session_id per domain. 我想要的是每个域1个session_id。 I'm having trouble changing session information in an ajax/php call in the php file because the session_id is different. 我在php文件中更改ajax / php调用中的会话信息时遇到问题,因为session_id不同。

there's a setup.php which is included in index.php and calledByAjax.php at the top of both files. 有一个setup.php ,它包含在index.php中并且在两个文件的顶部都有一个名为 ByAjax.php的文件。 In setup.php I run SESSION_START() . setup.php中,我运行SESSION_START()

Below explains the problem in code. 下面解释代码中的问题。

domain.com/helpers/ Setup.php domain.com/helpers/ Setup.php

session_start();

domain.com/ index.php domain.com/ 的index.php

include("helpers/settings.php" );
echo session_id(); // output: c4eapvno37vg027aba4pk2gl06

<script>
ajax.open("POST", "http://www.domain.com/calls/calledByAjax.php.php", true);
// response output: asdf98asdfahasdfl
</script>

domain.com/ calledByAjax.php domain.com/ calledByAjax.php

echo session_id();

Sessions are unique to a domain name because cookies are. 会话对于域名是唯一的,因为cookie是。 You can, however, share a session cookie over multiple subdomains, provided that the main domain enforces a www subdomain and if you prefix the cookie name with a dot: 但是,您可以在多个子域上共享会话cookie,前提是主域强制执行www子域,并且如果您在cookie名称前加一个点:

http://php.net/manual/en/function.session-set-cookie-params.php http://php.net/manual/en/function.session-set-cookie-params.php

$domain

Cookie domain, for example 'www.php.net'. Cookie域,例如“www.php.net”。 To make cookies visible on all subdomains then the domain must be prefixed with a dot like '.php.net'. 要在所有子域上显示cookie,域必须以“.php.net”之类的点为前缀。

The problem was in the ajax call. 问题出在ajax调用中。 I called to http:// www .domain.com/--- from http://domain.com/---- 我从http://domain.com/上打电话到http:// www .domain.com / ---

ajax.open("POST", "http://domain.com/calls/calledByAjax.php.php", true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM