Server-Side Presence Check in PHP

There are a couple of reasons you might want to do server-side presence checks. It lets you avoid having to deal with any library compatibility issues, it improves your page load time by not requiring the users to download the client-side presence API code, and it lets you avoid that little flash of "requires javascript" or "we're offline" before your true presence is displayed. These are all good things. The only real drawback is that we can't generate your code for you. Here's a quick example of how you might go about doing server-side presence in PHP.

Requires PHP ver 5, could be ported to ver 4

<?php
  $doc = new DOMDocument();
  $doc->load('https://libraryh3lp.com/presence/jid/YOUR-QUEUE/chat.libraryh3lp.com/xml');
  $show = 'unavailable';
  $resources = $doc->getElementsByTagName('resource');
  if ($resources->length > 0) {
    $show = $resources->item(0)->getAttribute('show');
  }
  if ($show == 'available' || $show == 'chat') {
    ?>You are available for chatting.<?php
  } else {
    ?>You are not available.<?php
  }
?>

Document URL: https://docs.libraryh3lp.com/code-presence-check-php.html

©2024 Nub Games, Inc.