XWeb: PHP

Important! Many of the code samples and links to code samples on this page were contributed in 2007. They may need to be modernized as PHP and xWeb have changed since then.

There are some reports that PHP and IIS have problems agreeing on the correct way to work over HTTPS, so occasionally PHP requests over HTTPS will work, but produce an error PHP Warning: SoapClient::__construct(): SSL: fatal protocol error. Usually the problem resolves itself within the hour, but each site installation is different and should be thoroughly tested before production use. Read more about the condition at php.net.

Also be aware that the connection timeout is determined by the php.ini default_socket_timeout setting, which defaults to 60 seconds. This can be overridden programatically by calling ini_set

When xWeb returns an Object that has results from an aliased table, the results come over as alias.pfx_col_name. Parsing the object xWeb returns into a SimpleXMLObject creates a PHP object with attributes named after the column names, but with an aliased table the period causes issues when retrieving the value. One workaround is to store the name of the column in a varible, and use the variable to retrieve the object value. For example:

print $exhibitor->ExhContact.cst_ind_full_name_dn; // throws error
$exh_cst_ind_full_name_dn = "ExhContact.cst_ind_full_name_dn";
print $exhibitor->$exh_cst_ind_full_name_dn ; //works successfully

If your xWeb results have been parsed by the SimpleXML library, note that most variables will be of an object type instead of a string or integer. For most uses implicit casting is sufficient, but remember that when setting an array key there is no implicit variable casting, and array keys may not be objects. For example:

print "The customer key is ".$cst->cst_key." and the org name is ".$cst->cst_org_name_dn;
// Outputs: The customer key is 9c0100ce-f6c2-4b42-aff2-1c065f3734d9 and the org name is test org name
$hash = array();
 
//INCORRECT:
$hash[$cst->cst_key] = $cst->cst_org_name_dn;
print $hash[$cst->cst_key];
// Throws invalid key warning
print_r($hash);
// returns an array with no keys
 
//CORRECT:
$hash[(string)$cst->cst_key] = $cst->cst_org_name_dn;
print $hash[$cst->cst_key];
// Outputs: test org name

Calling Authenticate with PHP

To see an example showing how to use PHP to set and get the Soap headers see the xWeb: Authenticate PHP Sample1 page.

xWebSecureClient

This shows a code snippet of how to call a web method in PHP using the media:PHP_xwebSecureClient_2007-01-25.zip. This code requires PHP 5.

The xwebSecureClient extends the PHP Soap class to transparantly implement the Authenticate method.

<?php
 
$nfUserName='NFUSERNAME'; //site specific
$nfUserPass='NFPASSWORD'; //site specific
 
$nfxweb = new xwebSecureClient("https://mynf.mywork.org//xweb/Secure/netFORUMXML.asmx?WSDL",
Array('trace'=>true, //turning on trace=true will let us grab the headers and responses
'exceptions'=>true,
'xwebUserName'=> $nfUserName,
'xwebUserPass'=> $nfUserPass));
print "Issuing bad request to xWeb\n";
try{
$response = $nfxweb->GetFacadeObject();
/* We're intentionally issuing a bad call here to xweb to demonstrate exception handling.
The xwebSecure Class has a string called log that gets appended to during actions, which we'll use to debug. A correct call would look like this:
$response = $nfxweb->GetFacadeObject(Array('szObjectKey'=>"899D54C8-2D34-4E8B-B276-000B80C8958E", 'szObjectName'=>'Individual'));
*/

 
}catch(SoapFault $exception){
print "****CAUGHT EXCEPTION: \n";
print "xwebSecure class log:\n";
print $nfxweb->log;
print "exception contents:\n";
print_r($exception);
print "soap headers, request and response strings:\n";
print_soap_debug($nfxweb);
}
 
//Now lets issue a good request
//Finding people by last name
print "\n\n\nUsing xWeb to find Individuals with last name like smit:\n";
$nfxweb->clearLog(); //we've already seen this, so no need to view it again.
try{
$response = $nfxweb->GetQuery(Array('szObjectName'=>'Individual',
'szColumnList'=>'ind_cst_key, ind_first_name, ind_mid_name, ind_last_name, cst_org_name_dn',
'szWhereClause'=>"ind_last_name LIKE 'smit%'",
'szOrderBy'=>"ind_last_name,ind_first_name"));
 
 
print "The response from GetQuery:\n";
print_r($response->GetQueryResult);
print "Loading the result into a SimpleXML object\n";
 
//under php 5.12 the simplexml_load_string options are different from those found on php.net
//I arrived at the following after some experimentation, but we're turning off the errors and the warnings since I haven't found a way to load the namespace
//before it loads the xml. If you remove these you'll see an error every time it loads an xml node with a namespace - which is most of them.
$queryXML = simplexml_load_string($response->GetQueryResult->any, "SimpleXMLElement", LIBXML_NOERROR+LIBXML_NOWARNING);
print "Printing the SimpleXML object";
print_r($queryXML);
 
$num_rows = $queryXML->attributes()->recordReturn;
 
print "Iterating over each individual object - there are $num_rows returned\n";
foreach ($queryXML->IndividualObject as $person){
print "Person ".$person->ind_full_name_cp." has a key of ".$person->ind_cst_key. "\n";
}
}catch(SoapFault $exception){
print "****CAUGHT EXCEPTION: \n";
print "xwebSecure class log:\n";
print $nfxweb->log;
print "exception contents:\n";
print_r($exception);
print "soap headers, request and response strings:\n";
print_soap_debug($nfxweb);
}
function print_soap_debug(&$soapclient){
//these soapclient methods are only available if it was constructed with trace=>true
print "Last Request Headers:\n";
print_r($soapclient -> __getLastRequestHeaders());
print "\nLast Request :\n";
print_r($soapclient -> __getLastRequest());
print "\nLast Response Headers :\n";
print_r($soapclient -> __getLastResponseHeaders());
print "\nLast Response :\n";
print_r($soapclient -> __getLastResponse());
print "\n";
}
?>

Additional Approach

Member Management API | Jason Leveille's Blog - A detailed case study of calling the Authenticate web method and other web methods in PHP.

See Also