Welcome to FindNerd. We are going to discuss the curl setup in php. In php curl is not enabled bydefault. You need to enable it via php.ini file. curl_init and curl_setopt
are the functions for main functionality. you can set the url by curl_ini and set the different options for calling. Please have a look.
$ch = curl_init($callingUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch,CURLOPT_REFERER,site_url());
curl_setopt($ch,CURLOPT_POST,true );
curl_setopt($ch,CURLOPT_POSTFIELDS,$request_array);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($ch);
curl_close($ch);
You can see in above example we set the url for execution and set the options such as HTTPHEADER,USERAGENT,RETURNTRANSFER etc.We set the return transfer true. It means
we will get the response. We set the false for ssl verification. we also posted data to other end by using CURLOPT_POST.
0 Comment(s)