为什么我的刷新标题不起作用?

发布于 2024-08-09 18:57:19 字数 459 浏览 2 评论 0原文

我正在使用 CGI.pm 模块在 Perl CGI 中完成家庭作业。在我的代码中,我正在检查 cookie。如果 cookie 存在,我想启动另一个 CGI 脚本。在其他情况下,我可以使用类似的代码,但在这种情况下,我只得到以下浏览器输出,而不是我正在寻找的重定向。

Refresh: 1; URL=homepage.pl.cgi
Content-Type: text/html; charset=ISO-8859-1

这是我的代码:

#get the cookie
my %SIDhash = cookie('SIDhash');

if ( exists $SIDhash{"SID"} ) {
    print header(-refresh=>'0; homepage.pl.cgi');
}

我在这里不理解哪些基本原理?

谢谢, CB

I'm working on a homework assignment in Perl CGI using the CGI.pm module. In my code I am checking for a cookie. If the cookie exists, I want to initiate another CGI script. In other situations I was able to use similar code, but in this instance I merely get the following browser output, not the redirect that I was looking for.

Refresh: 1; URL=homepage.pl.cgi
Content-Type: text/html; charset=ISO-8859-1

Here's my code:

#get the cookie
my %SIDhash = cookie('SIDhash');

if ( exists $SIDhash{"SID"} ) {
    print header(-refresh=>'0; homepage.pl.cgi');
}

What fundamentals am I not understanding here?

Thanks,
CB

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情何以堪。 2024-08-16 18:57:19

这应该可以解决问题:

print header(
    -refresh => '0; url=homepage.pl.cgi',
    -cookie => $cookie,
);

如果您要在代码中的各个位置将标头分段组装,请首先将标头组件保存在变量中,例如:

my %headers;

# later...
$headers{-cookie} = $cookie;

# later still:
if (exists $SIDhash{SID})
{
    # we want to redirect, so print all headers and we're done.
    print header(%headers, -refresh => '0; url=homepage.pl.cgi');
    exit;
}

# if we're still here, nothing is printed yet.. continue preparing data and print when ready.
# ...

This should do the trick:

print header(
    -refresh => '0; url=homepage.pl.cgi',
    -cookie => $cookie,
);

If you are assembling the header in pieces, in various places in your code, save the header components in a variable first, e.g.:

my %headers;

# later...
$headers{-cookie} = $cookie;

# later still:
if (exists $SIDhash{SID})
{
    # we want to redirect, so print all headers and we're done.
    print header(%headers, -refresh => '0; url=homepage.pl.cgi');
    exit;
}

# if we're still here, nothing is printed yet.. continue preparing data and print when ready.
# ...
嘿嘿嘿 2024-08-16 18:57:19

我不确定为什么你的刷新不起作用,但听起来使用它会更合适:

HTTP/1.1 302 Found
Location: http://www.example.org/

只是一个想法。

I'm not sure why your refresh doesn't work, but it sounds like it would be more appropriate to use:

HTTP/1.1 302 Found
Location: http://www.example.org/

Just a thought.

难以启齿的温柔 2024-08-16 18:57:19

尝试将行更改为

print header(-refresh=>'0; url=homepage.pl.cgi');

据我所知,现在应该是正确的。

维基百科上的此页面提供有关刷新和其他重定向方法的信息。

Try changing the line to

print header(-refresh=>'0; url=homepage.pl.cgi');

From what I can tell, this should be correct now.

This page on Wikipedia offers information on Refresh and other methods of redirection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文