gpt4 book ai didi

perl - 为什么Perl的CGI::cookie能够在IE中设置cookie,但不能在Firefox中设置cookie?

转载 作者:行者123 更新时间:2023-12-04 18:15:42 24 4
gpt4 key购买 nike

我有一些Perl CGI代码,试图在SourceForge帐户的项目Web空间中运行。该代码能够在与IE通话时很好地设置浏览器cookie,但与Firefox通话时cookie设置为而不是。当我在“localhost”上使用Apache进行测试时,两种浏览器都可以正常工作。 Firefox只能在远程SourceForge URL上使用。

搜索发现了数十个几乎重复的问题,但通常人们遇到的正是完全相反的问题! (Firefox很好,IE出现了问题)

这是我要用来设置Cookie的实用工具子目录:

sub setCookie {
my $name = shift;
my $value = shift;
my $expires = shift;
my $path = shift;
my $domain = shift;
if( !defined( $expires ) ) {
$expires = '+4h';
}
if( !defined( $path ) ) {
$path = '/';
}
if( !defined( $domain ) ) {
$domain = 'steveperkins.sourceforge.net';
}
my $cookie = CGI::cookie(
-name => $name,
-value => $value,
-domain => $domain,
-expies => $expires,
-path => $path
);
$r->header_out('Set-cookie' => $cookie);
}

有任何想法吗?我的第一个想法是某种子域问题,因为我的SourceForge项目URL中有一个子域,而“localhost”则没有。我已经尝试过将Cookie域设置为特定的子域,或仅设置为基本的“sourceforge.net”。两种方法似乎都没有什么不同。

更新:以下注释中的某人询问有关HTTP响应 header 的信息。我已经使用网络流量分析器工具Wireshark来监视IE和Firefox的请求和响应 header ,如下所示:

IE(工程)

要求
GET http://myproject.sourceforge.net/cgi-bin/myscript.cgi?page=user&userID=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://myproject.sourceforge.net/cgi-bin/myscript.cgi
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; InfoPath.1; .NET CLR 3.0.30618)
Proxy-Connection: Keep-Alive
Host: myproject.sourceforge.net
Authorization: Basic [password omitted]

回复
HTTP/1.1 200 OK
Server: nginx/0.7.63
Date: Tue, 26 Oct 2010 18:23:49 GMT
Content-Type: text/html; charset=ISO-8859-1
Expires: Thu, 28 Oct 2010 18:23:49 GMT
Cache-Control: max-age=172800, proxy-revalidate
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Content-Encoding: gzip
Set-Cookie: USER=1; domain=myproject.sourceforge.net; path=/

Firefox(无效)

要求
GET http://myproject.sourceforge.net/cgi-bin/myscript.cgi HTTP/1.1
Host: myproject.sourceforge.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Cookie: __utma=191645736.1501259260.1287701281.1288028150.1288100562.10; __utmz=191645736.1288101011.10.10.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=sourceforge%20project%20web%20space%20basic%20auth; _jsuid=4215309712123065236
Authorization: Basic [password omitted]

回复
HTTP/1.1 200 OK
Server: nginx/0.7.63
Date: Tue, 26 Oct 2010 18:17:58 GMT
Content-Type: text/html; charset=ISO-8859-1
Expires: Thu, 28 Oct 2010 18:17:58 GMT
Cache-Control: max-age=172800, proxy-revalidate
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Content-Encoding: gzip
Age: 0

最佳答案

我想说的是,您在设置到期时间时遇到了一个错误

if( !defined( $path ) ) {
$expires = '/';
}

应该
if( !defined( $path ) ) {
$path = '/';
}

更新:根据您上面使用wireshark提供的信息,我将检查Firefox进入时是否确实调用了setCookie。在网址上)。还要尝试在两个浏览器中使用相同的URL,然后看看会发生什么。

关于perl - 为什么Perl的CGI::cookie能够在IE中设置cookie,但不能在Firefox中设置cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com