<?php
$params = array(
'api_user' => 'YOUR_USERNAME',
'api_pass' => 'YOUR_PASSWORD',
'api_action' => 'singlesignon',
'api_output' => 'serialize',
'sso_addr' => '127.0.0.1',
'sso_user' => 'admin',
'sso_pass' => md5('adminspassword'),
'sso_duration' => 30,
);
$query = "";
foreach( $params as $key => $value ) $query .= $key . '=' . urlencode($value) . '&';
$query = rtrim($query, '& ');
$url = rtrim($url, '/ ');
if ( !function_exists('curl_init') ) die('CURL not supported. (introduced in PHP 4.0.2)');
if ( $params['api_output'] == 'json' && !function_exists('json_decode') ) {
die('JSON not supported. (introduced in PHP 5.2.0)');
}
$api = $url . '/api.php?' . $query;
$request = curl_init($api);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
$response = (string)curl_exec($request);
curl_close($request);
if ( !$response ) {
die('Nothing was returned. Do you have a connection to Help Desk server?');
}
$result = unserialize($response);
echo 'Result: ' . ( $result['result_code'] ? 'SUCCESS' : 'FAILED' ) . '<br />';
echo 'Message: ' . $result['result_message'] . '<br />';
if ( $result['result_code'] ) {
$sampleurl = $url . '/admin/main.php?_ssot=' . $result['token'];
echo 'A sample link your visitor can use to auto-login:<br />';
echo '<a href="' . $sampleurl . '">' . $sampleurl . '</a>';
}
echo 'The entire result printed out:<br />';
echo '<pre>';
print_r($result);
echo '</pre>';
echo 'Raw response printed out:<br />';
echo '<pre>';
print_r($response);
echo '</pre>';
echo 'API URL that returned the result:<br />';
echo $api;
?>