【问题标题】:Executing php script in perl with GET variables in url在 url 中使用 GET 变量在 perl 中执行 php 脚本
【发布时间】:2015-05-08 20:40:48
【问题描述】:

我有一个执行 php 脚本的 perl 脚本:

my $phpOutput = `/usr/bin/php /bart/bart.php`;

这工作得很好。现在我想在 url 中添加一些变量。

my $phpOutput = `/usr/bin/php /bart/bart.php?data=1`;

这失败了。

Could not open input file: /bart/bart.php?data=1

任何想法为什么?

【问题讨论】:

  • 在这种情况下,我不认为它真的是一个 URL。
  • 看起来它只是在shell中执行它。不能使用php.net/manual/en/reserved.variables.argv.php
  • 去掉问号再添加/试试?
  • @anantkumarsingh 如何解决问题?
  • This answer 有一种有趣的方式来处理这个问题。但看起来您需要以一种或另一种方式更改 PHP 脚本才能处理以这种方式调用它。

标签: php perl


【解决方案1】:

?x=y 语法适用于 Web 服务器,而 CLI 需要在文件名后用空格分隔的参数。按照您的编写方式,PHP 认为 ?data=1 是文件名的一部分。

你可以这样做

my $phpOutput = `/usr/bin/php /bart/bart.php 1`;

并使用$argv 数组从PHP 脚本中检索参数1。因为它是第一个参数,所以它将是 $argv[1](第 0 个索引是脚本名称)。

【讨论】:

  • 好的,谢谢。现在,如果“1”是一个变量怎么办......我的 $phpOutput = /usr/bin/php /bart/bart.php $someVar;这行得通吗?
  • 当然,我认为没有理由不这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
  • 1970-01-01
  • 2019-03-03
相关资源
最近更新 更多