• About Us
  • Blog
  • Basket
  • Account
  • Sign In

PHP V3.1 Documentation

You are viewing an old version of the documentation. For the latest, please go here: PHP V3.2

Advanced Usage

How to get Properties by Profile ID?

The following snippet is a working template for a page that displays a text field. In the text field you can input a profile ID and if the ID was found in the data file the relevant information will be displayed. Otherwise an error message will be displayed.

require_once 'core/51Degrees.php';

//Check if ID is supplied.
if (isset($_POST['profileId']) && !empty($_POST['profileId'])) {
	$profileId = intval($_POST['profileId']);
	//Load headers.
	$headers = fiftyone_degrees_get_headers();
	//Search for profile by ID.
	$profile = fiftyone_degrees_get_profile_from_id($profileId, $headers);
	//If nothing was found $profile will be NULL, otherwise it will be an array.
	if ($profile != NULL) {
		//Profile found, get values associated with it.
		$profile_values = fiftyone_degrees_get_profile_property_values($profile, $properties, $headers);
	} else {
		//Profile not found, set up the error message.
		$temp = $_POST['profileId'];
		$error_message = "No profile with id ".$temp." found";


	<form action="index.php" method="POST">
	Profile ID:<br>
	<input type="text" name="profileId" value="">
	<input type="submit" value="Find">
	//Check that profile values are not empty.
	if (!empty($profile_values)) {
		echo "<h2>Device information for profile ".$profileId.":</h2>";
		foreach($profile_values as $key => $value) {
			echo "<p>Property: ".$key." = ".$value."</p>";	
	//Check is error message is set. Indicates Profile was not found.
	if (isset($error_message)) {
		echo $error_message;

The above code should produce result similar to the following:
result of executing 51Degrees PHP API device detection functionality for finding profile properties by id