My Account | Buy CometChat

documentation

Hosting CometChat on a separate server/sub-domain

CometChat has full cross-domain support. You can run CometChat on a separate server, domain/sub-domain. Note, some plugins like page translation may not work when used in cross-domain environment.

An ideal use of this feature is when you want to load CometChat on a separate server e.g. chat.yoursite.com and want to use CometChat on www.yoursite.com.

Perform the following steps:

Modify your getUserID() function so that it is similar to below. The “basedata” value will be sent when the user logs into to your main domain.

function getUserID() {
    $userid = 0;

    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }

    if (!empty($_REQUEST['basedata'])) {
        $userid = $_REQUEST['basedata'];
    }

    return $userid;
}
  • Edit cometchat/config.php and set BASE_URL to the full path e.g. http://chat.yoursite.com/cometchat/
  • Then set CROSS_DOMAIN to 1

Cross domain support

  • Add the following code to the site template (remember to include the full URL path).

Add the code immediately after <head> tag:

<script>
var userid = 'USERID'; // Must be populated programmatically
document.cookie = "cc_data="+userid;
</script>
<link type="text/css" rel="stylesheet" media="all" href="http://chat.yoursite.com/cometchat/cometchatcss.php" /> 
<script type="text/javascript" src="http://chat.yoursite.com/cometchat/cometchatjs.php" charset="utf-8"></script>

Use of CometService or alternatives is strongly recommended when using CometChat in cross-domain environment. This guide will work for custom coded sites only.