PHP curl_setopt() function

curl_setopt is used to set an option for a curl transfer. It returns a boolean value.

Syntax of curl_setopt() -

bool curl_setopt(resource $ch, int $option, mixed $value);
$ch is the cURL Handler. $option specifies a cURL option and value specifies a value of the option. This is a list of options available at the PHP Official site - http://php.net/manual/en/function.curl-setopt.php

Example

<?php
    $ch = curl_init(); // Initialize Curl
    curl_setopt($curl_handle, CURLOPT_URL,'http://site-url.com');
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE );
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE );
    curl_setopt($curl_handle, CURLOPT_COOKIEJAR, './cookie.txt');
    curl_setopt($curl_handle, CURLOPT_COOKIEFILE, './cookie.txt');
    curl_setopt($curl_handle, CURLOPT_HEADER, FALSE );
    $buffer = curl_exec($curl_handle);//Execute curl command
    echo $buffer;
    curl_close($curl_handle);//Close curl and free resource
?>		

In the above example, these are the descriptions of options -

CURLOPT_URL - To fetch the url.
CURLOPT_SSL_VERIFYPEER - It is TRUE by default. If its value set to FASLE , then it stops from verifying the peer's certificate.
CURLOPT_RETURNTRANSFER - TRUE to return the curl_exec value as string.
CURLOPT_COOKIEJAR - To save all internal cookies to external file.
CURLOPT_COOKIEFILE - File contains cookie data.
CURLOPT_HEADER - It sets to TRUE to include HEADER in the output.



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language