0

I am using wamp with PHP version 5.5.12. I am trying to use http_response_code to set the code. When I use it, it returns true and not the value I set. I am a PHP newbie, and I wanted to know what I am missing in this. How do I get it to return 300 and not true?

getCode(300); // returns true and not with the code I set.

function getCode($code)
{
  $statuscode = http_response_code($code);
  echo $statuscode;
}
LadyT
  • 649
  • 2
  • 12
  • 31
  • You can read the docs. If you specify/set a new code then you will get the previous status code. Call the method http_response_code again with no arguments to get the new code. – Andreas Jan 24 '17 at 16:19
  • You mean this http://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code#12018482 or? – JustOnUnderMillions Jan 24 '17 at 16:19
  • 1
    Possible duplicate of [PHP: How to send HTTP response code?](http://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code) – carmine Jan 24 '17 at 16:22
  • @Andreas I did exactly what you said and ran it a second time without params. It worked. Thank You. – LadyT Jan 24 '17 at 16:27
  • @Andreas I did read the docs first. I was unclear, so I needed help. There's nothing wrong with asking questions. – LadyT Jan 24 '17 at 16:31

1 Answers1

0

I suggest you read the doc regarding http_response_code: http://php.net/manual/en/function.http-response-code.php

TRUE will be returned if response_code is provided and it is not invoked in a web server environment (but only when no previous response status has been set).

Having true means "Ok, we'll send 300" and is therefore fine in your case.

Antony
  • 1,253
  • 11
  • 19