开发者

What would cause a PHP response to have some extra whitespace at the beginning?

I have identical code on my production and local *AMP servers.

I've created a webservice that returns JSON in the response.

However, on my production platform, when the service responds, I get an extra whitespace (a tab) at the beginning of my response. Even after removing the output for the JSON, there is a tab at the beginning of the file. If I exit; completely from the beginning of the script that creates the JSON response, the whitespace goes away. There isn't any other place that I can see that would add this extra whitespace, and it doesn't add it in my development sandbox.

Is there something I'm missing? Has anyone ever has this problem?

Here's some of the code I'm using:

require_once('includes/config.php');

function checkIfExists($parameterName) {
    if (!isset($_REQUEST[$parameterName])) {
        throw new AppException("Missing parameter '$parameterName'");
    }

    if (!$value = trim($_REQUEST[$parameterName])) {
        throw new AppException("Missing parameter '$parameterName'");
    }

    return $value;
}

try {
    //my try block, this is where i create an array and then echo o开发者_运维百科ut a json_encoded string
} catch (AppException $e) {
    //my catch block here
}


We can't really accurately diagnose without seeing the code in its entirety, but check files for white space before the opening <?php tag, as that will be sent to the browser as well. I've had this happen a few times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜