Alex Rivera | Logout

Set $_SERVER variable when calling PHP from command line?

Asked 2012-05-24T04:31:13.273
30

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

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

Edit
Report

1 Answer

44

On *nix:

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

<?php

print_r($_SERVER);

Test:

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

[recipient] => something@example.com

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

$ export recipient="email@example.com"
$ setenv recipient="email@example.com"
answered 2012-05-24T05:18:45.857

Your Answer