Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

How a Non-Technical User Can Solve apache_request_headers Not Working

5 min read
20.04.2025

If you're a non-technical user encountering the problem of apache_request_headers not working in PHP, it might seem overwhelming. However, you can follow this detailed guide to fix the issue step by step, even without system administration expertise. The goal here is to address common scenarios and work within the limits of your hosting environment or application.

Fix apache_request_headers for Non-Technical Users
apache_request_headers() for non-developers — diagnosing without SSH.

For the developer-side, sysadmin-side, and verification angles, see How a Programmer Can Solve Issues with apache_request_headers in PHP, Fixing apache_request_headers Authorization Not Working — A System Administrator's Guide, Verifying Apache Configuration for apache_request_headers, and Solving apache_request_headers Issues on NGINX.

This guide is written for users without technical background. All steps are explained in simple language with minimal technical jargon.

What is apache_request_headers?

The PHP function apache_request_headers() is used to retrieve HTTP headers sent to your server (e.g., Authorization, Content-Type). If this function doesn't work, your script might fail to receive critical information, such as API keys or tokens.

Verify Your Hosting Environment

Before troubleshooting, you need to understand your hosting setup:

1. Shared Hosting:

Most users on shared hosting cannot modify server configurations directly. Your options are limited to code changes and contacting support.

2. VPS/Dedicated Hosting:

If you have a VPS or dedicated server, but no admin skills, contact your hosting provider's support team.

If you're on shared hosting, the hosting provider typically controls the server settings, so proceed to Step 3.

Check if apache_request_headers is Available

PHP's apache_request_headers() only works when PHP is running as an Apache module. If your hosting provider uses PHP-FPM or CGI, this function won't work.

How to Check:

  1. Create a new PHP file called check_headers.php in your project directory:
    <?php
    if (function_exists('apache_request_headers')) {
        echo "apache_request_headers() is available.";
    } else {
        echo "apache_request_headers() is NOT available.";
    }
    ?>
  2. Visit the file in your browser:
    http://yourwebsite.com/check_headers.php
    • If you see "apache_request_headers() is NOT available", skip to Step 4 to use alternatives.

Contact Your Hosting Provider

If you're on shared hosting and apache_request_headers() isn't working:

  1. Open a support ticket with your hosting provider.
  2. Ask them to:
    • Enable the Apache headers module (mod_headers).
    • Pass the Authorization or other headers to PHP.

Use this template to contact support:

Subject: Request to Enable Apache Headers Module

Message:

Hello,

I'm experiencing an issue with my PHP application where apache_request_headers() does not work. Could you please ensure that:

  • The mod_headers module is enabled in Apache.
  • The Authorization header and other HTTP headers are passed to PHP.

Thank you!

Wait for their response. In the meantime, proceed with Step 4 to handle the issue in your code.

Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Use PHP Alternatives

If you can't get apache_request_headers() to work, you can use $_SERVER to access HTTP headers directly. This is the easiest fix you can implement yourself.

Code to Replace apache_request_headers:

Replace any occurrence of apache_request_headers() in your PHP code with the following:

// Fallback function for headers
function getRequestHeaders() {
    if (function_exists('apache_request_headers')) {
        return apache_request_headers();
    }

    // Manual header retrieval for non-Apache setups
    $headers = [];
    foreach ($_SERVER as $key => $value) {
        if (strpos($key, 'HTTP_') === 0) {
            $headerName = str_replace('_', '-', substr($key, 5));
            $headers[$headerName] = $value;
        }
    }
    return $headers;
}

// Example usage
$headers = getRequestHeaders();
echo "Authorization Header: " . ($headers['Authorization'] ?? 'Not Found');

This method works on any server, regardless of whether apache_request_headers() is available.

Check Your .htaccess File

If your website uses an .htaccess file (common in PHP applications like WordPress or Laravel), ensure it isn't blocking the required headers.

Steps:

  1. Open the .htaccess file in the root folder of your website.
  2. Add the following lines at the top:
    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  3. Save the file and reload your website.

If you don't have access to .htaccess or don't know how to edit it, ask your hosting provider for help.

Test with a Debugging Script

After making changes, create a new script to test if headers are being received:

Debugging Script (debug_headers.php):

<?php
// Print all headers
$headers = function_exists('apache_request_headers') ? apache_request_headers() : $_SERVER;
echo "<pre>";
print_r($headers);
echo "</pre>";
?>

Test with cURL:

Use the curl command to send a request with headers:

curl -H "Authorization: Bearer test_token" http://yourwebsite.com/debug_headers.php

You should see the Authorization header in the output.

What You Should Do If You're Stuck

  • If editing .htaccess or PHP files feels too technical, ask your developer or hosting provider for assistance.
  • Provide clear examples of the issue (e.g., a script or error message).
  • Always back up your files before making any changes.

Summary

  1. Check if apache_request_headers is available using a test script.
  2. Contact your hosting provider to enable the Apache headers module and pass headers.
  3. Replace apache_request_headers with a fallback function using $_SERVER.
  4. Edit the .htaccess file to pass missing headers like Authorization.
  5. Test the solution with debugging tools (e.g., cURL).
  6. If nothing works, consider switching to a better hosting plan.

By following this guide, you can resolve the issue even without advanced technical knowledge.

Frequently asked questions
If you log in to a control panel (cPanel, DirectAdmin, Plesk) and see a single account with quotas/limits — shared. If you have SSH/root access to the entire server — VPS. Shared hosting customers can't change server-wide config; they need to ask support.
"My application needs the HTTP Authorization header to reach PHP. On Apache+PHP-FPM this requires either CGIPassAuth on, or a SetEnvIf/RewriteRule forwarding HTTP_AUTHORIZATION. Could you confirm which is enabled and, if neither, add CGIPassAuth on to my account's .htaccess scope?" Specifying the directive name signals you know what to ask for and shortens the back-and-forth.
Most shared hosts allow Header and SetEnvIf in .htaccess; some lock them down via AllowOverride None. If the rules in .htaccess don't take effect (verify with curl -I), the hosting provider has restricted .htaccess and you're back to filing a ticket.
On most setups yes — $_SERVER['HTTP_AUTHORIZATION'] gives the same value if Apache/NGINX forwards it. apache_request_headers() is convenient because it returns a clean assoc array; $_SERVER is the messier but more portable source. Many frameworks fall back to $_SERVER when apache_request_headers() is unavailable.
Related articles
How a Programmer Can Solve Issues with apache_request_headers in PHP
WordPress: Server Doesn't Have ImageMagick or GD Installed/Enabled
Understanding the .cagefs Folder in CloudLinux (cPanel Hosting)