Here is a slightly more complicated login/logout code snippet:
PHP Code:
<?php
if(!defined('sugarEntry'))define('sugarEntry', true); // allow this file as an entry point
require_once('include/nusoap/nusoap.php'); //use the nusoap library
//define the SOAP Client and point to the SOAP Server
$client = new nusoapclient('http://yourCrmUrl/soap.php?wsdl',true);
//prepare the authentication array which contains the username and password
$user_auth = array( 'user_name'=>"admin",
'password' =>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
'version' =>"4.5.0");
//send the authentication info and application name to the login function
$session = $client->call('login', array('user_auth'=>$user_auth, 'application_name'=>'SugarCRM'));
//check to see if any login errors occurred
$error = $session['error'];
if ($error['number']<>0){
echo "Login Error!<br />Error: ".$error['name']."<br />Descr: ".$error['description']."<br />";
} else {
//if no errors then output the session id
echo "Session id: ".$session['id']."<br />";
}
//PERFORM OTHER FUNCTIONS HERE
//log out of the session
$error = $client->call('logout', $session['id']);
//check to see if any logout errors occured
if ($error['number']<>0){
echo "Logout Error!<br />Error: ".$error['name']."<br />Descr: ".$error['description']."<br />";
} else {
//if no errors then output the session id
echo "Session Closed Successfully.<br />";
}
//kill the client
unset($client);
?>
Bookmarks