简体   繁体   English

运行“ php -f index.php”时在输出中返回标题

[英]Return headers in output when running “php -f index.php”

I tried searching around to find an answer to this but to no avail. 我试图四处搜寻以找到答案,但无济于事。

I have a simples PHP script with the below code: 我有一个包含以下代码的简单PHP脚本:

<?php
header("Content-Type: application/json");
echo "Hello";
?>

I then execute the file using the below command: 然后,使用以下命令执行文件:

php -f index.php

and the output is: 输出为:

Hello

My question is, is it possible to return the header I outputted using PHP, so my expected output would be something like: 我的问题是,是否有可能返回我使用PHP输出的标头,所以我的预期输出将是这样的:

Content-Type: application/json

Hello

You can achieve this by using php-cgi without the -f option: 您可以使用不带-f选项的php-cgi来实现:

php-cgi index.php
X-Powered-By: PHP/7.3.3
Content-Type: application/json

Hello

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM