首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP会话丢失,suhosin不可更改

PHP会话丢失,suhosin不可更改
EN

Stack Overflow用户
提问于 2013-10-24 01:11:25
回答 3查看 1.1K关注 0票数 0

在Ubuntu12.04上,安装了Apache2、PHP5服务器和suhosin扩展。(phpinfo页面)

这是一个通过自动更新获得最新安全更新的专用服务器。

我创建了以下测试脚本(不设置suhosin conf的测试脚本)

代码语言:javascript
复制
session_start();

$error = 0;
ob_implicit_flush(true);

if ($_GET['is'] == 'set'){
    session_set_cookie_params ( '3600','/','.theparentingplace.com',false, false );
    error_log( "Old 'suhosin.session.encrypt': " . print_r( ini_set('suhosin.session.encrypt', 0), true) );    
    error_log( "Old 'suhosin.session.cryptdocroot': " . print_r( ini_set('suhosin.session.cryptdocroot', 0), true) );    
    error_log( "Old 'suhosin.cookie.cryptdocroot.': " . print_r( ini_set('suhosin.cookie.cryptdocroot', 0), true) );
}



if (empty($_SERVER['HTTPS']) && !$error){
    $_SESSION['test'] = 'abc';
    header('Location: https://'.$_SERVER['SERVER_NAME']
     .'/http_https_session_test.php');

}else{
    if ($_SESSION['test'] == 'abc'){
        print "Success." . $_SESSION['test'];
    }else{
        print "Fail.". print_r($_SESSION['test'],1);
    }
}

错误日志显示:

代码语言:javascript
复制
[Sat Oct 26 20:00:23 2013] [error] [client 103.29.31.35] Old 'suhosin.session.encrypt': 
[Sat Oct 26 20:00:23 2013] [error] [client 103.29.31.35] Old 'suhosin.session.cryptdocroot': 
[Sat Oct 26 20:00:23 2013] [error] [client 103.29.31.35] Old 'suhosin.cookie.cryptdocroot.'

其他帖子建议检查session.cookie_secure和session.http_only参数。这两台服务器都关机了。此外,我试图实现关闭特定的suhosin设置,或者使用suhosin.simulation=On完全关闭suhosin --我在php.ini中都尝试了这一点。

此脚本返回失败。如果脚本使用is=set参数运行,则无法设置参数(测试脚本2)。

在另一台专用服务器上,测试脚本工作得很好。https url获取会话变量,但是这个服务器是Ubuntu10.04。

知道接下来该怎么做吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-27 18:53:55

最近,我将HTTPS文件合并为一个文件,并出于安全考虑将apache服务器更改为MPM。

在合并的VirtualHost文件中

代码语言:javascript
复制
<VirtualHost 120.138.18.91:80>
    ServerName www.theparentingplace.com

    DocumentRoot /var/www/www.theparentingplace.com/joomla
    CustomLog /var/log/apache2/www.theparentingplace.com-access.log   combined
    ErrorLog /var/log/apache2/www.theparentingplace.com-error.log

<IfModule mpm_itk_module>
    AssignUserId www-theparentingplace www-theparentingplace
</IfModule>

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^.*=(ht)|(f)+(tp)+(://|s://)+.*(\?\?)+
    RewriteRule .* http://gggooooooglleee.com/ [R,L]

    <FilesMatch "images/\.(asp|php|php5|pl)$">
        Deny from all
    </FilesMatch>
</VirtualHost>

<VirtualHost 120.138.18.91:443>
ServerName www.theparentingplace.com
    DocumentRoot /var/www/www.theparentingplace.com/joomla

CustomLog /var/log/apache2/www.theparentingplace.com-ssl-access.log combined
ErrorLog /var/log/apache2/www.theparentingplace.com-ssl-error.log

<IfModule mpm_itk_module>
    AssignUserId www-theparentingplace www-theparentingplace
</IfModule>

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/www.theparentingplace.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
    SSLCertificateChainFile /etc/apache2/ssl/www.theparentingplace.com.ca.crt

BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

   RewriteEngine On
   RewriteCond %{QUERY_STRING} ^.*=(ht)|(f)+(tp)+(://|s://)+.*(\?\?)+
   RewriteRule .* http://gggooooooglleee.com/ [R,L]

   <FilesMatch "images/\.(asp|php|php5|pl)$">
       Deny from all
   </FilesMatch>
</VirtualHost>

我忘了添加

代码语言:javascript
复制
<IfModule mpm_itk_module>
    AssignUserId www-theparentingplace www-theparentingplace
</IfModule>

块到安全站点部分,因此https站点无法读取会话文件。

感谢Brian,他让我想到了检查是否可以强制使用https的session_id (我无法使用错误的配置)。

票数 1
EN

Stack Overflow用户

发布于 2013-10-26 06:33:53

您试图更改的选项(例如,suhosin.cookie.cryptdocroot)会影响Suhosin在脚本开始运行之前所做的事情。因此,在运行时更改它们是没有意义的--您需要在php.ini或类似的环境中设置它们。

票数 1
EN

Stack Overflow用户

发布于 2013-10-26 06:34:18

session_start()输出任何内容之前,必须调用-因此在if ($_GET['is'] == 'set')块中,print调用会阻止会话的启动。没有这一点,$_SESSION['test']将永远不会持久到足以测试if ($_SESSION['test'] == 'abc')块是否为真。编辑:必须在任何输出之前发送所有标头(这也是必须在此之前调用session_start()的原因)--因此,ini_set块中的print调用仍然阻塞了header( 'location' ... )调用。如果您需要查看ini_set()返回的内容,请通过error_log( "Old 'suhosin.session.encrypt': " . print_r( ini_set('suhosin.session.encrypt', 0), true) );将其值输出到每个配置的错误日志中。或缓存结果,并在发送任何可能的头后对其进行print

http和https之间的传输也会丢失您的会话变量,因为它们会启动单独的会话。这个问题应该涵盖你的其他问题。在PHP中从HTTP切换到HTTPS时丢失的会话

对于您的suhosin... ini设置,ini_set将返回前面的值--所以如果ini配置以前是false,那么即使调用成功,也会得到false

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19555153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档