Set $_SERVER variable when calling PHP from command line?

前端 未结 5 2013
有刺的猬
有刺的猬 2020-12-25 12:05

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 e

5条回答
  •  悲&欢浪女
    2020-12-25 12:43

    The answer by @sberry is correct.

    ...but because I came to this page looking for setting default values for the $_SERVER array, when running PHP from command line, here is my own answer. Hope it might help somebody.

    empty( $_SERVER['HTTP_HOST'] ) && $_SERVER['HTTP_HOST'] = 'localhost';
    empty( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] = '/';
    empty( $_SERVER['DOCUMENT_ROOT'] ) && $_SERVER['DOCUMENT_ROOT'] = __DIR__;
    print_r( $_SERVER );
    

提交回复
热议问题