Set extra header
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
We released a new version of the Java API client in public beta. Read the beta documentation for more information.
About this method
Send an extra HTTP header to Algolia for use with later queries.
This method allows you to send the server a specific key-value pair (an extra HTTP header) with every query. By doing this, you are giving the API an additional header that it can be used in situations such as:
X-Forwarded-Forfor analytics. If your server sends the end user’s IP along with every search, analytics can distinguish between users. Otherwise, analytics uses the server’s IP address, which doesn’t provide user details. Alternatively, see the following
X-Algolia-UserTokenfor analytics. The Analytics API uses the provided value to distinguish between users. It takes priority over any value in
X-Forwarded-For. Use this header if you need to forward the end user’s identity without relying on IP addresses.
X-Algolia-UserTokenfor API key rate limiting.
X-Forwarded-Forto ensure that geo-search locations use the user’s IP address, not your backend server’s. For an example of this, see the
set extra header method will eventually be replaced by the
requestOptions parameter, allowing you to set the header as part of your query parameters.
Read the Algolia CLI documentation for more information.
1 2 3 4 5 6 $config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('YourApplicationID', 'YourWriteAPIKey'); $config->setDefaultHeaders([ 'headerName' => 'headerValue' ]); $client = \Algolia\AlgoliaSearch\SearchClient::createWithConfig($config);
Name of the header to add.
Value of the header to add.
This method doesn't return a response.