This is something new that may help out a lot of PHP Salesforce developers. The original code of this small script was given to me by David Claiborne, which I have since modified. What this does is it gives the developer a central location for their login information to salesforce so if you have to change your password or key, you can do it in on location instead of doing it in every script. If you are like me and have all of your internal legacy systems running on various scripts, you do not need to go to each script and manually change each username, password, and key. It just makes it that much easier.
PHP Code:
<?php
//Use the full path to your phptoolkit location incase you have scripts
//running on CRON
require_once ('/users/msimonds/public_html/includes/soapclient/SforcePartnerClient.php');
require_once ('/users/msimonds/public_html/includes/soapclient/SforceHeaderOptions.php');
// Login to salesforce.com
$login = "me@email.com";
$password = "password";
$key = "B68ZFlLOssO1t2RcYpTRC5wIo";
//use the full path in case you have scripts running on CRON
$wsdl = "/users/msimonds/public_html/includes/soapclient/partner.wsdl.xml";
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
try
{
$loginResult = $client->login($login, $password.$key);
if ($loginResult->passwordExpired)
{
unset($client);
}
}
catch (exception $e)
{
$error = '<pre>' . print_r($e, true) . '</pre>';
mail('masimonds@gmail.com', 'Salesforce Login Error', $error);
unset($client);
}
?>
then in your scripts you can use
PHP Code:
include_once ('/your/path/to/salesforce_login.inc');
and you should not have any issues logging into Salesforce at all. I have to be honest, it really makes life that much easier to have it installed in one location.
Thanks!
~Mike
Bookmarks