How to login and get session id using soap api in suitecrm

Here is the soap request which you can use to login into your suitecrm via soap api.

$xml = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sug="http://www.sugarcrm.com/sugarcrm" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <sug:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <user_auth xsi:type="sug:user_auth">
            <user_name xsi:type="xsd:string">'.USER_NAME.'</user_name>
            <password xsi:type="xsd:string">'.PASSWORD.'</password>
         </user_auth>
         <application_name xsi:type="xsd:string"></application_name>
         <name_value_list xsi:type="sug:name_value_list" SOAP-ENC:arrayType="sug:name_value[]"/>
      </sug:login>
   </soapenv:Body>
</soapenv:Envelope>';

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://suitecrm.localhost/service/v4_1/soap.php',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_SSL_VERIFYHOST=>0,
    CURLOPT_FRESH_CONNECT=>true,
    CURLOPT_SSL_VERIFYPEER=>0,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>$xml,
    CURLOPT_HTTPHEADER => array(
        'Content-Type: text/xml'
    ),
));

$response = curl_exec($curl);
// Close curl handle
curl_close($curl);
echo '<pre>';
print_r($response) ;