I have small HTTP server script that receives HTTP client requests and replies. I need to detect when there is \r\n\r\n type of ending. This happens when we have an input like this:
GET / HTTP/1.1
Host: test.com
Connection: close
I need to stop reading after the “Connection: close” double return hit. I tried with strpos and other string functions, but it is not working. Any hints to detect this kind of string ending in PHP?
Thanks.
For that specific protocol you can just look for empty lines with:
Actually you should be looking for
\r\n(and\nfor buggy clients), but other combinations are unlikely to occur. So anything with just whitespace is not a valid header line anymore.