explaingit

ralouphie/getallheaders

3,797PHPAudience · developerComplexity · 1/5Setup · easy

TLDR

A tiny PHP library that makes the getallheaders() function work on nginx and FastCGI servers, not just Apache, a one-line drop-in fix for a common PHP compatibility gap.

Mindmap

mindmap
  root((getallheaders))
    What it does
      HTTP header access
      Cross-server fix
      Apache polyfill
    Tech stack
      PHP
      Composer
    Use cases
      nginx compatibility
      FastCGI support
      Header reading
    Setup
      One Composer command
      No dependencies
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Make PHP code that reads HTTP headers work on nginx or FastCGI without rewriting any of your existing calls.

USE CASE 2

Fix a 'call to undefined function getallheaders()' error when deploying a PHP app to a non-Apache server.

USE CASE 3

Add a portable HTTP header reader to a PHP library or framework so it works on any web server setup.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This is a small PHP library that solves a specific compatibility problem. PHP has a built-in function called getallheaders() that retrieves all the HTTP headers sent with an incoming web request. The problem is that this function only works when PHP is running as an Apache web server module. When PHP runs under other server setups, such as nginx or as a FastCGI process, the function is not available and calling it causes an error. This library provides a substitute version of getallheaders() that works in those other environments by reading the same header information from a different place (the $_SERVER variable, which PHP populates regardless of how it is running). If you install this library, your code can call getallheaders() the same way regardless of which web server is being used underneath. A drop-in replacement like this is commonly called a polyfill. You install it using Composer, which is the standard PHP package manager, with a single command. The library is intentionally minimal: it does one thing and has no dependencies beyond PHP itself. The README is short because the library is short.

Copy-paste prompts

Prompt 1
I'm getting 'call to undefined function getallheaders()' on my nginx server. Show me how to install ralouphie/getallheaders with Composer and drop it into my existing PHP code.
Prompt 2
How do I use the getallheaders polyfill in a PHP project to safely read all HTTP request headers and return them as an associative array, regardless of which web server is running?
Prompt 3
I'm writing a PHP middleware that logs every incoming HTTP header for debugging. Show me how to use this library to make the code work on both Apache and nginx without any if-else checks.
Prompt 4
Write a PHP helper function that uses this library to extract a specific header by name from an incoming request, returning null if it is not present.
Prompt 5
Explain what the $_SERVER variable is in PHP and how this polyfill uses it to replicate the Apache-only getallheaders() behavior.
Open on GitHub → Explain another repo

← ralouphie on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.