• <i id='ghtLo'><tr id='ghtLo'><dt id='ghtLo'><q id='ghtLo'><span id='ghtLo'><b id='ghtLo'><form id='ghtLo'><ins id='ghtLo'></ins><ul id='ghtLo'></ul><sub id='ghtLo'></sub></form><legend id='ghtLo'></legend><bdo id='ghtLo'><pre id='ghtLo'><center id='ghtLo'></center></pre></bdo></b><th id='ghtLo'></th></span></q></dt></tr></i><div id='ghtLo'><tfoot id='ghtLo'></tfoot><dl id='ghtLo'><fieldset id='ghtLo'></fieldset></dl></div>

    1. <legend id='ghtLo'><style id='ghtLo'><dir id='ghtLo'><q id='ghtLo'></q></dir></style></legend>

        <bdo id='ghtLo'></bdo><ul id='ghtLo'></ul>
        <tfoot id='ghtLo'></tfoot>
      1. <small id='ghtLo'></small><noframes id='ghtLo'>

        PHP 多域会话;ini_set 不工作?

        PHP Multi-Domain Sessions; ini_set Not Working?(PHP 多域会话;ini_set 不工作?)
            <tbody id='WdruH'></tbody>
          • <bdo id='WdruH'></bdo><ul id='WdruH'></ul>

          • <tfoot id='WdruH'></tfoot>
            <i id='WdruH'><tr id='WdruH'><dt id='WdruH'><q id='WdruH'><span id='WdruH'><b id='WdruH'><form id='WdruH'><ins id='WdruH'></ins><ul id='WdruH'></ul><sub id='WdruH'></sub></form><legend id='WdruH'></legend><bdo id='WdruH'><pre id='WdruH'><center id='WdruH'></center></pre></bdo></b><th id='WdruH'></th></span></q></dt></tr></i><div id='WdruH'><tfoot id='WdruH'></tfoot><dl id='WdruH'><fieldset id='WdruH'></fieldset></dl></div>

              • <small id='WdruH'></small><noframes id='WdruH'>

                <legend id='WdruH'><style id='WdruH'><dir id='WdruH'><q id='WdruH'></q></dir></style></legend>

                1. 本文介绍了PHP 多域会话;ini_set 不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试设置它,因此如果您登录到我的网站,会话会转移到我网站的所有子域.例如,如果您转到 domain.com 并登录,然后转到 sub.domain.com,则您已经在 sub.domain.com 上登录了.

                  I'm trying to set it up so if you log in to my website the session carries over to all sub-domains of my website. For example, if you go to domain.com and log in, then go to sub.domain.com, you'll already be logged in at sub.domain.com.

                  据我所知,您可能想使用 ini_set('session.cookie_domain','.domain.com') 然后 session_start(),然后设置会话变量,但这不起作用.

                  To my understanding, you would want to use ini_set('session.cookie_domain','.domain.com') and then session_start(), then set your session variables, but this isn't working.

                  我正在做的事情的例子:

                  Example of what I'm doing:

                  domain.com 的代码:

                  Code for domain.com:

                  <?php
                   ini_set('session.cookie_domain','.domain.com');
                   session_start();
                   $_SESSION['variable'] = 1;
                  ?>
                  

                  sub.domain.com 的代码:

                  Code for sub.domain.com:

                  <?php
                   session_start();
                   echo $_SESSION['variable'];
                  ?>
                  

                  但是 $_SESSION['variable'] 没有设置.

                  But $_SESSION['variable'] isn't set.

                  我也试过在 sub.domain.com 代码中使用 ini_set(),但没有任何区别.我已经通过使用 ini_get() 验证了设置 session.cookie_domain 是否有效.

                  I've also tried using ini_set() in the sub.domain.com code, but it made no difference. I've verified that setting session.cookie_domain is working by using ini_get().

                  我做错了什么?谢谢!

                  推荐答案

                  先验证ini_set

                  <?php
                  ini_set('session.cookie_domain','.domain.com');
                  
                  echo ini_get('session.cookie_domain');
                  
                  session_start();  
                  $_SESSION['variable'] = 1; 
                  
                  ?> 
                  

                  <小时>

                  更新:

                  刚刚想了一下..你也试过吗:

                  Just thought about it.. Did you also try:

                  <?php
                  
                  session_set_cookie_params( 0, "/", ".domain.com", false, false); 
                  session_start();  
                  $_SESSION['variable'] = 1; 
                  
                  ?> 
                  

                  <小时>

                  更新 2:替代处理(手动 cookie 处理)


                  Update 2: ALternate handling (manual cookie handling)

                  <?php
                  
                  session_start();  
                  session_regenerate_id();
                  $_SESSION['variable'] = "String Test";
                  
                  setcookie('PHPSESSID',session_id(),time()+86400,'/','.domain.com');
                  echo session_id();
                  ?> 
                  

                  并在子域文件中

                  <?php  
                  if (isset($_COOKIE['PHPSESSID']) && !empty($_COOKIE['PHPSESSID'])) session_id($_COOKIE['PHPSESSID']);
                  
                  session_start();  
                  echo $_SESSION['variable'] . "<br />"; 
                  echo $_COOKIE['PHPSESSID'] . "<br />";
                  echo session_id();
                  ?> 
                  

                  <小时>

                  您可以在每个文件中添加三行来传递/处理会话信息


                  Three lines you could add to every file to hand off / handle session info

                  if (isset($_COOKIE['PHPSESSID']) && !empty($_COOKIE['PHPSESSID'])) session_id($_COOKIE['PHPSESSID']);
                  session_start();  
                  if (!isset($_COOKIE['PHPSESSID'])) setcookie('PHPSESSID',session_id(),time()+86400,'/','.domain.com');
                  

                  您通过会话传递了哪些信息?或者你用它来处理登录等?

                  What info are you passing through the session? Or are you using it to handle logins, etc?

                  这篇关于PHP 多域会话;ini_set 不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <tfoot id='WKt6W'></tfoot>

                    • <small id='WKt6W'></small><noframes id='WKt6W'>

                      • <bdo id='WKt6W'></bdo><ul id='WKt6W'></ul>

                          <legend id='WKt6W'><style id='WKt6W'><dir id='WKt6W'><q id='WKt6W'></q></dir></style></legend>

                        1. <i id='WKt6W'><tr id='WKt6W'><dt id='WKt6W'><q id='WKt6W'><span id='WKt6W'><b id='WKt6W'><form id='WKt6W'><ins id='WKt6W'></ins><ul id='WKt6W'></ul><sub id='WKt6W'></sub></form><legend id='WKt6W'></legend><bdo id='WKt6W'><pre id='WKt6W'><center id='WKt6W'></center></pre></bdo></b><th id='WKt6W'></th></span></q></dt></tr></i><div id='WKt6W'><tfoot id='WKt6W'></tfoot><dl id='WKt6W'><fieldset id='WKt6W'></fieldset></dl></div>
                            <tbody id='WKt6W'></tbody>