checkAPIkey (function)

Last updated: Fri, Apr 14, 2023 4:59 pm
Return to Knowledgebase

Purpose

Used to validate the format an API key entered by a user

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $key string Yes The key whose formatting you wish to check

Further Documentation:

The function takes one parameter: $key, which is the API key entered by the user to validate.

The function initializes an empty string called $msg, which will store a message to return to the user based on the validation result.

If $key is empty, the function sets $msg to a message encouraging the user to enter their API key to enable certain features.

If $key is not empty, the function uses two regular expressions to validate the format of the key. The regular expressions check that the key is a string of 5 alphanumeric characters, followed by a hyphen, and repeated 5 times for a total of 25 or 24 characters. If the key does not match either of these patterns, the function sets $msg to an error message indicating that the key is not valid.

If $key matches one of the valid patterns, the function sets $msg to a success message indicating that the key is valid.

Finally, the function returns the message stored in $msg.

Overall, this function provides a simple way to validate an API key entered by a user, and can be used to provide feedback to the user about the validity of their input.