我可以从 Perl CGI 脚本重定向到 PHP 页面吗?

发布于 2024-08-31 05:42:23 字数 273 浏览 0 评论 0原文

我正在使用一个使用外部源来处理支付交易的网站,先决条件之一是成功调用 CGI 脚本。

我想知道是否可以使用 CGI 脚本重定向到 PHP 页面,并让 PHP 检测到它已通过 Perl 重定向加载,目前我的 Perl 中有此内容。

#!/usr/bin/perl
#
# fixedredir.cgi

use strict;
use warnings;


my $URL = "http://www.example.com/";

Location: $URL;

I am working with a site that uses an outside source to work with payment transactions, one of the prerequisites is that on success a CGI script is called.

What I am wanting to know is it possible to do a redirect to a PHP page with the CGI script and have the PHP detect that it has been loaded via a Perl redirect, I currently have this is in my Perl.

#!/usr/bin/perl
#
# fixedredir.cgi

use strict;
use warnings;


my $URL = "http://www.example.com/";

Location: $URL;

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

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

发布评论

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

评论(4

天邊彩虹 2024-09-07 05:42:23

在 Perl 中进行 CGI 编程的标准方法是使用 CGI.pm 模块。
重定向可以这样编码(不确定语法)。

 #!/usr/bin/perl

 use strict;
 use warnings;
 use CGI;

 my $URL = "http://www.example.com/";

 print CGI::redirect($URL); 

我并不关心目标页面是 PHP 还是其他页面。

另一个页面无法确定它是否来自“perl 重定向”(实际上这个概念相当荒谬)。如果您可以控制其他 PHP 页面,则可以设置一些约定并在查询字符串中传递参数。

 my $URL = "http://www.example.com/x.php?redirectFromPerl=1";

更新:正如其他人所评论的那样,这个问题确实没有什么意义 - 并且一些陈述(“成功时调用 CGI 脚本”)暗示了对动态网页和 CGI​​ 基础知识的一些基本误解。我的示例代码展示了如何在 Perl CGI 中进行重定向,但原始问题(以及答案)可能不足以满足实际场景。

The standard way to do CGI programming in Perl is using the CGI.pm module.
A redirect can be coded like this (not sure about the syntax).

 #!/usr/bin/perl

 use strict;
 use warnings;
 use CGI;

 my $URL = "http://www.example.com/";

 print CGI::redirect($URL); 

I does not matter if the target page is PHP or whatever.

The other page can't know for sure if it came from a "perl redirect" (actually the concept is rather absurd). If you have control over the other PHP page, you can set some convention and pass a parameter in the query string.

 my $URL = "http://www.example.com/x.php?redirectFromPerl=1";

Update : As others have commented, the question really makes little sense - and some statements ("on success a CGI script is called") suggest some basic misunderstandings about the basics of dynamic web pages and CGI. My example code shows how to make a redirect in Perl CGI, but it's probable that the original question (and hence the answer) is inadequate for the real scenario.

南风起 2024-09-07 05:42:23

如果这是调用 CGI 脚本的外部源,它如何知道它调用的是您站点上的 PHP 页面还是 CGI 脚本?对我来说,您只需设置此支付服务即可调用您的 PHP 页面,并避免任何重定向要求。还是有什么我没明白的地方?

如果它在您的网站上查找特定的 URL,例如 /cgi-bin/trigger.cgi,您可以将 .htaccess 放入 cgi-bin 中来欺骗它,像这样:

<Files trigger.cgi>
    SetHandler application/x-httpd-php
</Files>

If this is an outside source that calls CGI script, how would it know if it is a PHP page or a CGI script on your site, that it calls? For me, you can just set up this payment service to call your PHP page and avoid any requirement for redirection. Or is there something I haven't understood?

If it looks for a specific URL on your site, e. g. /cgi-bin/trigger.cgi, you can trick it with .htaccess put in cgi-bin, like this:

<Files trigger.cgi>
    SetHandler application/x-httpd-php
</Files>
慕烟庭风 2024-09-07 05:42:23

最简单的方法是向您的 URL 添加一个 get 变量:

my $URL = "http://www.example.com/?from=perl"; 

这样您的 PHP 就不需要做任何花哨的事情了。但是,您可以查看 $_SERVER['HTTP_REFERER'] 值并解析引用脚本的名称。但由于该值是由用户代理设置的,因此它不一定可靠或存在。

the easiest way would be to add a get variable to your URL:

my $URL = "http://www.example.com/?from=perl"; 

then your PHP doesn't have to do anything fancy. However, you can look at the $_SERVER['HTTP_REFERER'] value and parse the referring script's name. But since this value is set by the user agent, it is not necessarily reliable or present.

书信已泛黄 2024-09-07 05:42:23

要将页面重定向到另一个页面,请使用以下方法。

use CGI::Session;
use CGI::Session::Plugin::Redirect;
my $session = new CGI::Session();
print $session->redirect('http://exsample.com/redirect-path/');

搜索search.cpan.org< /a> 有关会话模块的更多详细信息。

To redirect a page to another use the following method.

use CGI::Session;
use CGI::Session::Plugin::Redirect;
my $session = new CGI::Session();
print $session->redirect('http://exsample.com/redirect-path/');

Search search.cpan.org for more details about the session module.

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