Set Extra Header
About this method
Sends an extra http header to Algolia, for all subsequent queries.
This method allows you to send the server a specific key/value pair - that we call an extra http header, with every query. By doing this, you are giving the api an additional header that it can later use in certain situations.
Here are some headers with different use cases:
X-Algolia-UserTokenfor API key rate limiting purposes.
X-Algolia-UserTokenfor analytics purposes. The Analytics API uses the provided value to distinguish between end 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-Forwarded-Forfor analytics purposes. If your server sends the end user’s IP along with every search, this lets analytics distinguish between end users. Otherwise, the analytics uses the server’s IP address, which doesn’t provide the detail of each user. Alternatively, see
X-Forwarded-Forfor geo purposes. This ensures that the geo search location uses the IP address of the end user, and not that of your back-end server. For an example of this, see the
This will eventually be replaced by the
requestOptions parameter, allowing you to set the header as part of your query parameters.
1 2 3 4 5 6 $config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('YourApplicationID', 'YourAdminAPIKey'); $config->setDefaultHeaders([ 'headerName => 'headerValue' ]); $client = \Algolia\AlgoliaSearch\SearchClient::createWithConfig($config);
Name of the header to add.
Value of the header to add.