$base64_code = base64_encode($client_id.":".$client_secret);
$ch = curl_init();
$request_headers = array();
$request_headers[] = 'Content-Type: application/x-www-form-urlencoded';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Authorization: Basic '.$base64_code;
$data_to_post = "grant_type=password&username=$username&password=$password";
curl_setopt($ch, CURLOPT_URL, "https://api.demdex.com/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_post);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$res = json_decode($result,true);
$access_token = $res['access_token'];