Signature
Parameters
The name of the HTTP header to read (case-insensitive)
Return Value
The value of the header as text, or NULL if the header is not present
Description
Theheader() function allows you to read HTTP headers from the incoming request. Header names are case-insensitive, so 'User-Agent' and 'user-agent' are equivalent.
Examples
Log User Agent
Record the browser’s User-Agent string in the database:Check Request Origin
Verify that a request comes from an allowed origin:Content Type Detection
Check if the client is requesting JSON:Get Real Client IP Behind Proxy
When running behind a reverse proxy:Common Headers
- User-Agent - Browser and OS information
- Accept - Content types the client can handle
- Accept-Language - Preferred languages
- Referer - The page that linked to this page
- Authorization - Authentication credentials
- Content-Type - Type of request body (for POST/PUT)
- Origin - Origin of cross-site requests
- X-Forwarded-For - Real client IP when behind a proxy
- X-Real-IP - Alternative header for client IP
Related Functions
- sqlpage.headers() - Get all headers at once as JSON
- sqlpage.cookie() - Read cookie values
- sqlpage.client_ip() - Get client IP address