function ryzom_error($err, $format = 'txt')
{
    switch ($format) {
        case 'txt':
            $res = $err;
            break;
        case 'simplexml':
            $res = simplexml_load_string("<error>{$err}</error>");
            break;
        case 'xml':
            $res = ryzom_error($err, 'simplexml')->asXML();
            break;
        case 'xmlgz':
            $res = gzencode(ryzom_error($err, 'xml'));
            break;
    }
    return $res;
}
if (isset($_GET['ckey']) && $_GET['ckey'] != '') {
    ryzom_log_start('example_profile');
    // Display the profile
    $ckey = $_GET['ckey'];
    $key = ryzom_decrypt($ckey);
    $uid = 0;
    $gid = 0;
    $slot = 0;
    $full = false;
    if (ryzom_character_valid_key($key, $uid, $slot, $full)) {
        $xml = ryzom_character_simplexml($key, 'full');
    } else {
        if (ryzom_guild_valid_key($key, $gid)) {
            $xml = ryzom_guild_simplexml($key);
        } else {
            $xml = ryzom_error('Not valid character or guild key', 'simplexml');
        }
    }
    if ($xml->getName() == 'error') {
        $content = '<div class="error">' . $xml . '</div>';
        $content .= '<hr/><a class="ryzom-ui-button" href="?">back</a>';
        die(ryzom_render_www(ryzom_render_window('API error', $content)));
    }
    // Display the profile
    if ((string) $xml->getName() == 'character') {
        $title = 'Character profile';
        $content = render_character($xml, $key);
    } else {
        $title = 'Guild profile';
        $content = render_guild($xml);
    }