Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BENderIsGr8te's avatar

Access raw php://input

Is it possible to access raw

php://input

I am refactoring an App originally written in CodeIgniter to L5. The app communicates in the most horrible SOAP implementation you've ever seen with one of the major Credit Bureaus. (Their API, not mine. It's the only one they offer, so we MUST use it).

Once a credit report is ready, the Credit Bureau's API simply posts raw XML to a URL of our choosing.

In CodeIgniter the security settings always prevented me from accessing the raw PHP input. Since it's not key/val posting there is no variable to assign it to, so it always shows up as an empty post request when using $_POST; Essentially the only way I found to access the XML was

$xml = file_get_contents('php://input');

In order to make it work, I had hack CI so that if a request was coming in to a specific URL it was going to a file that existing outside the framework so I could process it (manually having to build up Database connections etc...). CI wouldn't even let me access php://input.

I am hoping in Laravel that I can either use Middleware to exempt a route and be able to access it via a built in method (or even the php://input isn't the end of the world).

I'll be preparing to build this part of my app in the next few weeks and I am just trying to plan ahead. (I still have to deal with all this SOAP BS that this place currently uses) (Side note, they are launching a RESTful API in July and will switch from Soap to JSON, but they are still just going to raw post it to a URL...annoying).

0 likes
4 replies
sitesense's avatar
Level 19

You should be able to use $request->getContent() for that.

4 likes
BENderIsGr8te's avatar

I literally just saw a StackOverflow page moments ago where someone mentioned that. I know that php://input can only be read once, and CI doesn't store that. I am going to test it out. if it works I'll mark this answered :)

sitesense's avatar

Here's the source:

public function getContent($asResource = false)
    {
        if (false === $this->content || (true === $asResource && null !== $this->content)) {
            throw new \LogicException('getContent() can only be called once when using the resource return type.');
        }

        if (true === $asResource) {
            $this->content = false;

            return fopen('php://input', 'rb');
        }

        if (null === $this->content) {
            $this->content = file_get_contents('php://input');
        }

        return $this->content;
    }
BENderIsGr8te's avatar

It works! Well, it worked after I add an exception for the route since there is no Token. However by the time I get to actually working with these posts I will be on L5.1 and the route exceptions are built in. Sweet! This will make my life MUCH easier than the hack I had to put together in CI.

Please or to participate in this conversation.