Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Denason's avatar

CURL not working in localhost :(

i have an api sms service codes that send Verification codes .

my codes work good in my host but the codes return false in localhost

my support service say that you have firewall problems

but i turn off firewall and define rules that open CURL port but now working yet.

i use wamp server last version and curl is installed and active and curl command working in my cmd the phpinfo return curl in enable.

0 likes
4 replies
Denason's avatar

class SmsIR_UltraFastSend {

/**
 * Gets API Ultra Fast Send Url.
 *
 * @return string Indicates the Url
 */
protected function getAPIUltraFastSendUrl()
{
    return "api/UltraFastSend";
}

/**
 * Gets Api Token Url.
 *
 * @return string Indicates the Url
 */
protected function getApiTokenUrl()
{
    return "api/Token";
}

/**
 * Gets config parameters for sending request.
 *
 * @param string $APIKey    API Key
 * @param string $SecretKey Secret Key
 * @param string $APIURL    API URL
 *
 * @return void
 */
public function __construct()
{
    $this->APIKey = '000000';
    $this->SecretKey = '00000';
    $this->APIURL = 'https://ws.sms.ir/';
}

/**
 * Ultra Fast Send Message.
 *
 * @param data[] $data array structure of message data
 *
 * @return string Indicates the sent sms result
 */
public function ultraFastSend($data)
{
    $token = $this->_getToken($this->APIKey, $this->SecretKey);
    if ($token != false) {
        $postData = $data;

        $url = $this->APIURL.$this->getAPIUltraFastSendUrl();
        $UltraFastSend = $this->_execute($postData, $url, $token);

        $object = json_decode($UltraFastSend);

        $result = false;
        if (is_object($object)) {
            $result = $object->Message;
        } else {
            $result = false;
        }
    } else {
        $result = false;
    }
    return $result;
}

/**
 * Gets token key for all web service requests.
 *
 * @return string Indicates the token key
 */
private function _getToken()

{
    $postData = array(
        'UserApiKey' => $this->APIKey,
        'SecretKey' => $this->SecretKey,
        'System' => 'php_rest_v_2_0'
    );
    $postString = json_encode($postData);

    $ch = curl_init($this->APIURL.$this->getApiTokenUrl());
    curl_setopt(
        $ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json'
        )
    );
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);

    $result = curl_exec($ch);
    curl_close($ch);

    $response = json_decode($result);

    $resp = false;
    $IsSuccessful = '';

    $TokenKey = '';

    if (is_object($response)) {
        $IsSuccessful = $response->IsSuccessful;
        if ($IsSuccessful == true) {

            $TokenKey = $response->TokenKey;
            $resp = $TokenKey;
        } else {
            $resp = false;
        }
    }
    return $resp;
}

/**
 * Executes the main method.
 *
 * @param postData[] $postData array of json data
 * @param string     $url      url
 * @param string     $token    token string
 *
 * @return string Indicates the curl execute result
 */
private function _execute($postData, $url, $token)
{
    $postString = json_encode($postData);

    $ch = curl_init($url);
    curl_setopt(
        $ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'x-sms-ir-secure-token: '.$token
        )
    );
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);

    $result = curl_exec($ch);
    curl_close($ch);

    return $result;
}
patrickcm's avatar

Basic rules of debugging apply here. We would need the same info to diagnose that you would. :)

What are the values of the results of curl_exec(), curl_getinfo() and curl_error()?

Please or to participate in this conversation.