bshaffer / oauth2-server-php

A library for implementing an OAuth2 Server in php
http://bshaffer.github.io/oauth2-server-php-docs
MIT License
3.26k stars 950 forks source link

Response status on IIS #861

Closed arturm11 closed 7 years ago

arturm11 commented 7 years ago

Response::send() doesn't set HTTP status in IIS FastCGI environment. My solution is to replace line: header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)); with (PHP >= 5.4): http_response_code($this->statusCode); or:

if (substr(php_sapi_name(), 0, 3) == 'cgi')
    header(sprintf('%s %s', $this->statusCode, $this->statusText));
else
    header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
bluebaroncanada commented 7 years ago

Did you actually check this with Wireshark? Can you try to log the value of statusCode? Something fishy about that.

arturm11 commented 7 years ago

Thank you for reply. After some more investigation I have found "cgi.rfc2616_headers = true" in my php.ini. Changing back to default solves the problem. BTW there was a bug in my workaround. It should be:

if (substr(php_sapi_name(), 0, 3) == 'cgi')
    header(sprintf('Status: %s %s', $this->statusCode, $this->statusText));
else
    header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));

See: https://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code

bluebaroncanada commented 7 years ago

Thank you for that update! Much appreciated.