2010-07-13 110 views
2

大家好!我有一个关于会议的问题,希望有人能帮助我。我有一个apache测试服务器,它使用http和https的虚拟主机。我把下面的文件在我的HTTPS和它的工作原理:虚拟主机会话问题

mytest.php:

// this starts the session 
session_start(); 
// this sets variables in the session 
$_SESSION['color']='red'; 
$_SESSION['size'] ='small'; 
$_SESSION['shape']='round'; 
echo "Done"; 

mytest2.php:

// this starts the session 
session_start(); 
// echo variable from the session, we set this on our other page 
echo "Our color value is ".$_SESSION['color']; 
echo "Our size value is ".$_SESSION['size']; 
echo "Our shape value is ".$_SESSION['shape']; 

但它并不当我查看复制工作HTTP。

phpinfo()函数中都是相同的:

session 
Session Support enabled 
Registered save handlers files user sqlite 
Registered serializer handlers php php_binary wddx 

Directive Local Value Master Value 
session.auto_start Off Off 
session.bug_compat_42 On On 
session.bug_compat_warn On On 
session.cache_expire 180 180 
session.cache_limiter nocache nocache 
session.cookie_domain no value no value 
session.cookie_httponly Off Off 
session.cookie_lifetime 0 0 
session.cookie_path// 
session.cookie_secure On On 
session.entropy_file no value no value 
session.entropy_length 0 0 
session.gc_divisor 100 100 
session.gc_maxlifetime 1440 1440 
session.gc_probability 1 1 
session.hash_bits_per_character 4 4 
session.hash_function 0 0 
session.name PHPSESSID PHPSESSID 
session.referer_check no value no value 
session.save_handler files files 
session.save_path /tmp /tmp 
session.serialize_handler php php 
session.use_cookies On On 
session.use_only_cookies Off Off 
session.use_trans_sid 0 1 
+0

“当我在http中查看副本时,它不起作用。”你能更具体一点吗?这两个脚本在不同的领域? – 2010-07-13 17:21:57

+0

没有。我使用的是http://192.168.1.101/mytest.php和http://192.168.1.101/mytest2.php,以及https://192.168.1.101/mytest.php和https://192.168.1.101/mytest2。 php – Lucas 2010-07-13 17:23:36

+1

你正在从http连接到https吗?尝试打印sessionid()以查看切换页面时会话ID是否更改... – 2010-07-13 17:23:36

回答

0

问题是这样的:

session.cookie_secure On On 

如果cookie的会话cookie的安全,它只会通过HTTPS通过发送客户端。

更改该INI设置或致电session_set_cookie_params之前session_start并指定有你不想要一个安全的饼干,例如:

session_set_cookie_params(0, '/', "example.com", false); 
+0

工作。谢谢!! – Lucas 2010-07-13 17:27:41

1

因为它已经说过,这可能是因为你使用安全饼干。

请注意,如果您不使用安全cookie,则需要小心应用程序的逻辑以强化其安全性。可以从HTTPS转到HTTP,但是应该放弃HTTPS会话。否则,攻击者可能会从HTTP连接中获取cookie并通过HTTPS连接使用它,假装被认证为合法用户。

+0

+1,以确保安全。你击败了我! – Timothy 2010-07-13 17:37:43