- Prerequisites
- Premium Data
- Getting Started
- Summary
- Distributions
- 51Degrees.php Config
- Using the Detector
- Advanced Usage
- Accessing Metadata
- Image Optimiser
- Client Side Overrides
- Passing Properties To Client Side
- User Performance Monitoring
- Usage Sharing
- Automatic Data Updates
- Advanced Suggestions
- Troubleshooting
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.
<?php require_once 'core/51Degrees.php' ; //Check if ID is supplied. if ( isset ( $_POST [ 'profileId' ]) && ! empty ( $_POST [ 'profileId' ])) { $profileId = intval ( $_POST [ 'profileId' ]); //Load headers. fiftyone_degrees_set_file_handle(); $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' ]; trim( strip_tags ( $temp )); $error_message = "No profile with id " . $temp . " found" ; } } ?> <html> <head> </head> <body> <form action="index.php" method="POST"> Profile ID:<br> <input type="text" name="profileId" value=""> <br><br> <input type="submit" value="Find"> </form> <div> <?php //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 ; } ?> </div> </body> </html>
The above code should produce result similar to the following: