从命令行调用PHP时设置$ _SERVER变量? [英] Set $_SERVER variable when calling PHP from command line?

查看:193
本文介绍了从命令行调用PHP时设置$ _SERVER变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过命令行将$ _SERVER变量传递给PHP脚本吗?

Is it possible to pass a $_SERVER variable to a PHP script via the command line?

具体来说,我试图设置$ _SERVER ['recipient']手动方式,所以我可以测试电子邮件管道,而不设置邮件服务器。

Specifically I am trying to set the $_SERVER['recipient'] manually so I can test email piping without setting up a mail server.

推荐答案

On * nix:

$ recipient="email@domain.com" php script.php

<?php

print_r($_SERVER);

测试:

$ recipient="email@domain.com" php script.php | grep recipient

[recipient] => something@domain.com

或者,您可以导出它或setenv(取决于您的操作系统),如

Or, you can export it or setenv (depending on your OS), like

$ export recipient="email@domain.com"
$ setenv recipient="email@domain.com"

这篇关于从命令行调用PHP时设置$ _SERVER变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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