0

I have some basic knowledge of PHP . Once I got an 500 internal error in my Localhost (XAMPP) and it was showing that the server is overloaded. After doing some R&D I got the solution.

I used

header('location : mypage.php') // Giving me 500 internal error

The solution was

header('location: mypage.php') // just removing the space between 'location' and ':'

So my Question is why it happened ? what is the difference between 'location : mypage.php' and 'location: mypage.php' ?

Arosha De Silva
  • 597
  • 8
  • 18
Pranbir Sarkar
  • 111
  • 1
  • 10
  • 7
    One's the correct [HTTP header syntax](https://tools.ietf.org/html/rfc7231#section-7.1.2) and the other isn't? – CD001 Jun 15 '18 at 10:46
  • 4
    One is valid, the other isn't. See [RFC7230](https://tools.ietf.org/html/rfc7230#page-22). PHP itself does some parsing for the `Location:` header and ignores invalid ones. – mario Jun 15 '18 at 10:46
  • According to [RFC7230 section-3.2](https://tools.ietf.org/html/rfc7230#section-3.2) Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace. – Arosha De Silva Jun 15 '18 at 10:57
  • "500 Internal Server Error" (or a blank page) means your script is throwing an error but PHP is configured to hide it from you. I recommend you fix it in your development box because coding without the aid of error messages is hard. As quick start, you can set the `error_reporting` and `display_errors` directives in your computer's system-wide `php.ini` file ([details here](http://stackoverflow.com/a/5680885/13508)). Errors thumb rule: show in development, log in production. – Álvaro González Jun 15 '18 at 11:10

1 Answers1

0

Quite simply, you have the wrong syntax when a space is included. It is part of the specifications, which you can read on the W3C site.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39