Note that there are some explanatory texts on larger screens.

plurals
  1. POLog in Salesforce using cURL in PHP
    text
    copied!<p>I'm building a login page from where I would like to connect to my salesforce.com account. The idea is that if the username/password is wrong, I leave the user on my website and otherwise I redirect him to the salesforce panel.</p> <p>To check if the username password exists, I use the Salesforce PHP Toolkit. And when I see that the user has entered a legit account, I use cURL to post the username and password to the form that is supposedly handling the login.</p> <p>Here's some bits of the code:</p> <pre><code>$url = 'https://login.salesforce.com/'; $fields = array( 'username' =&gt; urlencode($username), 'pw' =&gt; urlencode($pw), 'un' =&gt; urlencode($username), 'width' =&gt; urlencode($width), 'height' =&gt; urlencode($height), 'hasRememberUn' =&gt; urlencode(true), 'startURL' =&gt; urlencode(''), 'loginURL' =&gt; urlencode(''), 'loginType' =&gt; urlencode(''), 'useSecure' =&gt; urlencode(true), 'local' =&gt; urlencode(''), 'lt' =&gt; urlencode('standard'), 'qs' =&gt; urlencode(''), 'locale' =&gt; urlencode('uk'), 'oauth_token' =&gt; urlencode(''), 'login' =&gt; urlencode(''), 'serverid' =&gt; urlencode(''), 'display' =&gt; urlencode('page') ); $fields_string =''; foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; } rtrim($fields_string,'&amp;'); $ch = curl_init(); /* Set the url, number of POST vars, POST data */ curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch, CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); $result = curl_exec($ch); curl_close($ch); </code></pre> <p>I inspected the source of the login page of salesforce.com to see what post values it needs which I put it in the code above.</p> <p>The problem is that whenever I input a valid account, it redirects me to the login page (so I am not logged in) of salesforce.com saying</p> <blockquote> <p>You have attempted to access a page that requires a salesforce.com login. If you are already a user of the system, please login below.</p> </blockquote> <p>Could anyone tell me what I'm doing wrong ?</p> <p>Cheers !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload