Knowledge base

PHP

How does it work?

To make use of Netbiscuits Server-Side PHP Device Detection, all you have to do is download the server-side client, configure it, and start using it.

A typical PHP Device Detection configuration code block will look something like this:

$account = "[account_name]";
$token = "[token]";
$profile = "[profile]";

With the PHP client configured, the following events happen when a user’s browser requests a page from your website:

  • Your server requests the Device Detection profile from a Netbiscuits Device Detection server
  • The Device Detection server runs a series of tests to identify the user’s device
  • A collection of parameters and values is created and returned to your server in JSON format
  • Device Detection can be set up to gather dynamic data within the user’s browser
  • Once complete, the Device Detection object can be used to customize the user’s experience for the exact device they are using

How can I use Netbiscuits PHP Device Detection?

  1. First of all, make sure you’ve created a Netbiscuits account and have logged in.
  2. If you’re all set there, then you need to download the PHP client.
  3. Next, copy your PHP configuration code.
  4. Once copied, paste that code block into nb-dd-config.php, something like:
    $account = "[account_name]";
    $token = "[token]";
    $profile = "[profile]";
    
  5. Once the PHP Device Detection client loads, all of the Device Detection parameters will be available in a global object called $dd.
  6. Finally, you are ready to use the Device Detection information in your code, for example:
    <dl>
      <dt>Device Type:</dt>
        <dd><?php echo $dd->devicetype; ?></dd>
      <dt>Device Model:</dt>
        <dd><?php echo $dd->model; ?></dd>
      <dt>Can this device play h264?:</dt>
        <dd><?php echo ($dd->h264) ? 'yes' : 'no'; ?></dd>
      <dt>Is this device touch-capable?:</dt>
        <dd><?php echo ($dd->touch) ? 'yes' : 'no'; ?></dd>
      <dt>What is the largest image width this device can display?:</dt>
        <dd><?php echo $dd->imagemaxwidth; ?></dd>
    </dl>
    

How do I configure dynamic parameter detection?

To detect dynamic parameters and make them available in your server side DeviceProfile Object, simply add another configuration value to nb-dd-config.php:

$dynamicParameterDetection = true;

By setting this field ‘true’, device detection will add a detection script into property $dd->javascriptdd; in case the user is visiting your site the first time.
Within your pages, check whether the $dd->javascriptdd; property is set, and send the value of this property back to the browser instead the content of the page itself. If that parameter is not set, send the page content.

<?php
    // Include the NB DD page
    include('nb-dd.php');
	
    if($dd->dynamicParameterDetection && $dd->javascriptdd) {
        echo $dd->javascriptdd;
    } else {
?>
    <html>
        <head></head>
        <body>
            <div>
                Hello World
            </div>
        </body>
     </html>
<?php
    }
?>

When the script is sent to the browser, it detects dynamic parameters, like display with and height and pixel ratio. After the detection, the script querys the same page again and sets some cookies. This ensures that the dynamic paramter set is injected into the device profile object.

Demos

To help you further with getting started, we have created a series of demos that you can download and run on your own server (including your localhost).

We hope this has helped you get up and running with the Netbiscuits PHP Device Detection. If you have any questions or need help with your setup, please contact us.

Or if you’re ready for the next step, find out about all the Device Detection Parameters you can build into your website!

Learn more about Device Detection Parameters

YouTube aktivieren?

Auf dieser Seite gibt es mind. ein YouTube Video. Cookies für diese Website wurden abgelehnt. Dadurch können keine YouTube Videos mehr angezeigt werden, weil YouTube ohne Cookies und Tracking Mechanismen nicht funktioniert. Willst du YouTube dennoch freischalten?