This example shows how to use the 51Degrees Cloud Service to determine details about a
device based on its User-Agent and User-Agent Client Hint HTTP header values.
This example shows how to use the 51Degrees Cloud Service to determine details about a
device based on its User-Agent and User-Agent Client Hint HTTP header values.
.
<?php
require_once(__DIR__ . "/../../vendor/autoload.php");
if (strtolower(basename(__FILE__)) == strtolower(basename($_SERVER["SCRIPT_FILENAME"])))
{
function main($argv)
{
$logger = new Logger("info");
$config = json_decode(file_get_contents(__DIR__."/gettingStartedConsole.json"), true);
$resourceKey = ExampleUtils::getResourceKeyFromCliArgs($argv);
if (empty($resourceKey)) {
$resourceKey = ExampleUtils::getResourceKeyFromEnv();
}
if (empty($resourceKey)) {
$resourceKey = ExampleUtils::getResourceKeyFromConfig($config);
}
if (empty($resourceKey)) {
$message = "No resource key specified in CLI args, environment variable '" .
ExampleUtils::RESOURCE_KEY_ENV_VAR . "', or configuration file." . PHP_EOL .
"The 51Degrees cloud service is accessed using a 'ResourceKey'. " .
"For more detail see " .
"/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-php&utm_content=examples-cloud-gettingstartedconsole.php&utm_term=resource-key-required. " .
"A resource key with the properties required by this " .
"example can be created for free at " .
"https://configure.51degrees.com/g3gMZdPY?utm_source=code&utm_medium=example&utm_campaign=51degrees-php&utm_content=examples-cloud-gettingstartedconsole.php&utm_term=resource-key-required. " .
"Once complete, populated the environment variable " .
"mentioned at the start of this message with the key.";
ExampleUtils::logErrorAndExit($logger, $message);
}
ExampleUtils::setResourceKeyInConfig($config, $resourceKey);
(new GettingStartedConsole())->run($config, $logger, [ExampleUtils::class, 'output']);
}
main(isset($argv) ? array_slice($argv, 1) : null);
}
Definition ExampleUtils.php:29
Definition classes/GettingStartedConsole.php:42