doppelme logo

Example Integration Code

Below are 4 example PHP files that illustrate how to integrate DoppelMe avatars within your website using the SOAP API. These are given for example only and no warranty is provided. These example are given in PHP - but the same prinicples can be applied to code in other languages/frameworks.

doppelme.php | profile_avatar.php | profile_avatar_create.php | profile_avatar_updated.php

Example page showing how to embed the avatar editor within your site

The main page which allows your users to edit their avatars
<?php session_start(); ?>

<?php include("doppelme.php"); ?>

<?php
    //these values have been read from your database on login
    $sCALLBACK_URL = urlencode("http://localhost/profile_avatar_updated.php");    

    
    //hard-coded here for testing - note casting to string to avoid bug in SimpleXML;
    $_SESSION['UserID'] = (String)1;

    //your user's id (i.e. the id that your site uses to identify your user)
    if( isset($_SESSION['UserID']) ) {
        $USER_ID = $_SESSION['UserID'];
    } else {
        //user hasnt logged in or session expired?
        header( 'Location: http://[www.yoursite.com]/please_login.php' ); 
    }

    //your user's doppelme avatar key (read this in from database - or session)    
    if( ! isset($_SESSION['DoppelMeKey'])  ) {
        //user doesnt have an avatar - redirect them to page where they can create one
        header( 'Location: ./profile_avatar_create.php' );         
    } else {
        $sDOPPELME_KEY = $_SESSION['DoppelMeKey'];
    }

    
    
    //retrieve the ValidationKey details for  this user's avatar (we need this to be able to edit their avatar)
    $sURL        = "GetDetailsFromPartnerUserID";    
    $sDATA    = array(
                "partner_id"     => $DM_PARTNER_ID,
                "partner_key"     => $DM_PARTNER_KEY, 
                "partner_user_id" => $USER_ID,
                "is_test"        => false        );


    $sReturnXML = PartnerServiceCall($sURL, array($sDATA) );
                        
    if ( $sReturnXML == "" ) {
        //no avatar found for these details - have you supplied the correct keys?        
        header( 'Location: http://[www.yoursite.com]/avatar_error.php' );
    }        
    

    $xmlDoc = simplexml_load_string( $sReturnXML->GetDetailsFromPartnerUserIDResult );
    $sVALIDATION_KEY = $xmlDoc->ValidationKey;
     
    $iframe_url =     $DOPPELME_SITE . "/partner/partner_validate.asp?stripped=yes&pid=" . $DM_PARTNER_ID . 
            "&puid=" . $USER_ID . "&validkey=" . $sVALIDATION_KEY . "&doppelmekey=" . $sDOPPELME_KEY . "&callback=" . $sCALLBACK_URL;
?>

<html>
<head>
</head>
<body>
    <div style="height: 450px;margin: 0 auto;">        
    <iframe src="<?php echo $iframe_url; ?>" 
        style="position:absolute;overflow:hidden;width:660px;height:450px;border: 0;border-collapse: collapse;margin: 0 auto;" 
    frameborder="0" marginwidth="0" marginheight="0" scrolling="no" vspace="5" hspace = "0"></iframe>
    </div>                
    
</body>
</html>