| 1 common.inc | backdrop_get_autocomplete_token($path) |
Generates a token for accessing an autocomplete callback.
The token is based on the exact path used for autocomplete requests, so a token generated for one autocomplete path cannot be used to access a different autocomplete path. For authenticated users, the token is also tied to the user's session. Because anonymous users normally do not have a session (and pages may be served from the page cache), tokens for anonymous users are the same for all anonymous users.
@since 1.35.2 Function added.
Parameters
string $path: The internal path used for the autocomplete requests, such as 'user/autocomplete'. This is usually the value of #autocomplete_path.
Return value
string: A URL-safe token.
See also
backdrop_valid_autocomplete_token()
File
- core/
includes/ common.inc, line 6542 - Common functions that many Backdrop modules will need to reference.
Code
function backdrop_get_autocomplete_token($path) {
$value = 'autocomplete:' . trim($path, '/');
if (!user_is_logged_in()) {
// Anonymous users usually do not have a persistent session, so the token
// cannot be tied to the session ID.
return backdrop_hmac_base64($value, backdrop_get_private_key() . backdrop_get_hash_salt());
}
return backdrop_get_token($value);
}