有没有从 PHP 脚本调用 CGI 脚本的好方法?

发布于 2024-07-13 16:33:15 字数 219 浏览 4 评论 0原文

我看到 PHP 中有一个 virtual() 函数可以调用 CGI 脚本,但这是最好的方法吗? 我也可以将任何参数传递给该脚本吗?

我看到一些使用 file_get_contents()include() 并传入 CGI 脚本 URL 的示例,但这感觉像是黑客攻击。

I saw that there is a virtual() function in PHP that will call a CGI script, but is that the best way? Can I pass any parameters to that scripts as well?

I saw some examples using file_get_contents() or include() and passing in the URL of a CGI script, but that feels like a hack.

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

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

发布评论

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

评论(2

人间☆小暴躁 2024-07-20 16:33:15

如果可以在本地调用,请使用 exec()。 如果它需要作为 CGI 调用(因为脚本被设计为仅在 CGI 环境中工作),那么您需要通过 include()file_get_contents( )virtual() 将刷新缓冲区并附加子请求的输出。

您可以通过 include()file_get_contents()virtual() 传递参数作为 GET 参数:

http://localhost/cgi-bin/foo?param1=val1¶m2=val2

如果可能,请转到 exec() 路线。 使用其他方法可能需要更改配置。

当使用 exec() 时,您需要传递参数就像任何 CLI 程序一样。

foo val1 val2
foo param1=val1 param2=val2

如何传递参数将取决于您稍后希望如何在其他程序/脚本中解析它们。 它们将显示在被调用的程序中,就像从命令行调用它一样。

Use exec() if you can call it locally. If it needs to be invoked as a CGI (as in the script is designed to only work within a CGI environment), then you'll need to call it via include() or file_get_contents(). virtual() will flush your buffers and append the output of the sub-request.

You can pass parameters through include(), file_get_contents(), and virtual() as GET parameters:

http://localhost/cgi-bin/foo?param1=val1¶m2=val2

If possible, go the exec() route. Using the other methods may require a config change.

When using exec(), you'll need to pass the arguments like you would for any CLI program.

foo val1 val2
foo param1=val1 param2=val2

How you pass the parameters in will depend on how you want to parse them out later in the other program/script. They'll show up in the called program like they would if you called it from the command line.

川水往事 2024-07-20 16:33:15

我在从 php 页面调用 CGI 脚本时也遇到了问题。 后来我意识到问题是我的页面文件具有 .html 后缀,而不是 .php 后缀。 解决这个问题使我的脚本可以为我工作。 这可能不是你的问题,但我想我应该提一下以防万一。

I was having trouble with calling a CGI script from my php page too. Later I realized that the issue was that my page file had the .html suffix, rather than the .php suffix. Fixing that allowed my script to work for me. This is probably NOT your problem, but I thought I'd mention it just in case.

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