How to host CometChat on a separate server/sub-domain?

CometChat v3.0.9 and higher versions, provides full cross-domain support.
Using this feature, you can run CometChat on a separate server or 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. and want to use it on

To host CometChat on a separate server/sub-domain, follow the steps listed below:

    1. Upload and configure CometChat on your sub-domain following the standard installation instructions.

    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;
    1. Edit cometchat/config.php and set BASE_URL to the full path e.g.

    1. Then set CROSS_DOMAIN to 1


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

    Add the code immediately after tag:

    var userid = 'USERID'; // Must be populated programmatically
    document.cookie = "cc_data="+userid;
    <link type="text/css" rel="stylesheet" media="all" href="" /> 
    <script type="text/javascript" src="" 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.

  • Not finding what you need?

    The CometChat team is here to help!