function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JMcIvorJMcIvor 

Failed Login Function PHP SOAP

We are experiencing an issue where sometimes we cannot log into SalesForce using the following code. It seems to work about 90-95% of the time, but every now and then it fails, and causes a 404 page – the error shown is “Could not connect to host.”. The username and password we’re using (i.e. $this->SF_username) are both valid as it works most of the time.

The issue seems to lie in the “$this->sforce->login” part of the following code, which I believe is handled on the SalesForce end. I can’t find any (code) declaration of that login() function in the “sforce” SoapClient object, though it is present in the “partner.wsdl.xml” XML file. I’ve tried assigning the result of “$this->sforce->login()” to a variable and printing it, but when the login() function fails, it doesn’t get that far, it just triggers the 404 page.

1)
file_one.php:
$mySforceConnection = $joomlaSf->getSFConnection();

2)
file_two.php:

function getSFConnection()
{
if ($mySforceConnection->createConnection(JPATH_BASE . '/custom_files/SF_sync/soapclient/partner.wsdl.xml')) {
$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->login($this->SF_username, $this->SF_password);
}
}

3)
SF_sync/soapclient/SforceBaseClient.php:
public function login($username, $password) {
$this->sforce->__setSoapHeaders(NULL);
if ($this->callOptions != NULL) {
$this->sforce->__setSoapHeaders(array($this->callOptions));
}
if ($this->loginScopeHeader != NULL) {
$this->sforce->__setSoapHeaders(array($this->loginScopeHeader));
}

// The following function seems to be causing the issue.
$result = $this->sforce->login(array (
'username' => $username,
'password' => $password
));

$result = $result->result;
$this->_setLoginHeader($result);
return $result;
}

Does anyone have any insight as to why this happens, and possible solutions to fix this?
AshesAshes
Hi,

Please check if Salesforce is expecting digital certificate to connect with SAlesforce allong with credentials. 
JMcIvorJMcIvor
We include the security token in the password if that's what you mean? The strange thing is that it works the majority of the time.