如何在PHP脚本中将参数从命令行传递到$ _POST? [英] How can I pass parameters from the command line to $_POST in a PHP script?

查看:71
本文介绍了如何在PHP脚本中将参数从命令行传递到$ _POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这听起来有些怪异,但是我需要将一些参数传递给 $ _ POST 数组.类似于 Apache 或任何其他Web服务器的方式.

I know this could sound a little weird, but I need to pass some parameters to the $_POST array. Similar to the way Apache does it, or any other web server.

不幸的是,我找不到 libapache2-mod-php5 到我的

Unfortunately I couldn't find libapache2-mod-php5 anywhere for my Ubuntu installation.

推荐答案

这不容易做到.您可以调用 php-cgi 二进制文件,并通过管道发送伪造的POST请求.但是您需要设置很多CGI环境变量:

That's not easily doable. You can invoke the php-cgi binary and pipe a fake POST request in. But you'll need to set up a whole lot of CGI environment variables:

echo 'var1=123&var2=abc' | REQUEST_METHOD=POST  SCRIPT_FILENAME=script.php REDIRECT_STATUS=CGI CONTENT_TYPE=application/www-form-urlencoded php-cgi 

注意:数量不足,无法正常运行.但是类似的东西...

Note: Insufficient, doesn't work like that. But something like that...

如果只修补脚本,并让它从预定义的环境变量中加载$ _POST数组,肯定会更容易.

It's certainly easier if you just patch the script, and let it load the $_POST array from a predefined environment variable.

$_POST = parse_url($_SERVER["_POST"]);

然后为简单起见,您可以像 _POST = var = 123 php script.php 一样调用它.

Then you can invoke it like _POST=var=123 php script.php for simplicity.

这篇关于如何在PHP脚本中将参数从命令行传递到$ _POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆