我可以从 Perl CGI 脚本重定向到 PHP 页面吗?
我正在使用一个使用外部源来处理支付交易的网站,先决条件之一是成功调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Perl 中进行 CGI 编程的标准方法是使用 CGI.pm 模块。
重定向可以这样编码(不确定语法)。
我并不关心目标页面是 PHP 还是其他页面。
另一个页面无法确定它是否来自“perl 重定向”(实际上这个概念相当荒谬)。如果您可以控制其他 PHP 页面,则可以设置一些约定并在查询字符串中传递参数。
更新:正如其他人所评论的那样,这个问题确实没有什么意义 - 并且一些陈述(“成功时调用 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).
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.
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.
如果这是调用 CGI 脚本的外部源,它如何知道它调用的是您站点上的 PHP 页面还是 CGI 脚本?对我来说,您只需设置此支付服务即可调用您的 PHP 页面,并避免任何重定向要求。还是有什么我没明白的地方?
如果它在您的网站上查找特定的 URL,例如
/cgi-bin/trigger.cgi
,您可以将.htaccess
放入cgi-bin 中来欺骗它
,像这样: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 incgi-bin
, like this:最简单的方法是向您的 URL 添加一个 get 变量:
这样您的 PHP 就不需要做任何花哨的事情了。但是,您可以查看
$_SERVER['HTTP_REFERER']
值并解析引用脚本的名称。但由于该值是由用户代理设置的,因此它不一定可靠或存在。the easiest way would be to add a get variable to your URL:
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.要将页面重定向到另一个页面,请使用以下方法。
搜索
search.cpan.org
< /a> 有关会话模块的更多详细信息。To redirect a page to another use the following method.
Search
search.cpan.org
for more details about the session module.