I am trying to test something in my website . How i can create the HTTP requests in PHP using code cURL,
This my code
public function test(){
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'exmaple.com:80/',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_HTTPHEADER => array('Content-Type:application/json','Authorization: Basic'),
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => "\n  {\n
                                            \"M\": \"\",\n
                                            \"A\": \"\"\n                          
                                        }",
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
        ));
        echo $response = curl_exec($curl);
        die();
    }
i have add this code in index.php file and i open link example.com/index.php but its shows error white page nothing happened !
<?php
 $curl = curl_init();
            curl_setopt_array($curl, array(
                CURLOPT_URL => 'exmaple.com:80/',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_HTTPHEADER => array('Content-Type:application/json','Authorization: Basic'),
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_POST => 1,
                CURLOPT_POSTFIELDS => "\n  {\n
                                                \"M\": \"\",\n
                                                \"A\": \"\"\n                          
                                            }",
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
            ));
            echo $response = curl_exec($curl);
            die();
        }
?> 
this error i am getting when i open the index.php
Notice: Undefined variable: curl in /var/www/html/index.php on line 5
Warning: curl_setopt_array() expects parameter 1 to be resource, null given in /var/www/html/index.php on line 6
Notice: Undefined variable: curl in /var/www/html/index.php on line 21
Warning: curl_exec() expects parameter 1 to be resource, null given in /var/www/html/index.php on line 21
How i can fix this?
 
    