Ivijan Stefan Stipić Ivijan Stefan Stipić - 3 months ago 14
PHP Question

How to transfer Twilio lookup cURL code to PHP cURL

I have this curl code:

curl -X GET https://lookups.twilio.com/v1/PhoneNumbers/(919) 410-7522\
-d "Type=carrier"
-u "{AccountSid}:{AuthToken}"


I try to convert in PHP cURL but I stack on how to send
AccountSid
and
AuthToken
.

I need this code only to check if number is valid and mobile or landline.

How to do that? Thanks!

Answer

Just use CURLOPT_USERPWD option

$ch = curl_init("https://lookups.twilio.com/v1/PhoneNumbers/(919)%20410-7522");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_POSTFIELDS, "Type=carrier");
curl_setopt($ch, CURLOPT_USERPWD, "{AccountSid}:{AuthToken}");
$response = curl_exec($ch);