Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Last active September 2, 2018 15:03
Show Gist options
  • Save tieutantan/d2563897ac65f02bc1ec91fb65573524 to your computer and use it in GitHub Desktop.
Save tieutantan/d2563897ac65f02bc1ec91fb65573524 to your computer and use it in GitHub Desktop.
PHP CURL example
<?php
$url = 'https://api.ipify.org/?format=json';
$ip = '129.146.70.253:80';
$request = curl_init();
curl_setopt_array($request, [
CURLOPT_URL => $url,
CURLOPT_PROXY => $ip,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_FAILONERROR => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, // http://stackoverflow.com/questions/31162706/
CURLOPT_COOKIEJAR => APPPATH . 'tmp' . DS . 'curl_cookie.txt',
CURLOPT_COOKIEFILE => APPPATH . 'tmp' . DS . 'curl_cookie.txt',
CURLOPT_REFERER => 'https://www.google.com/',
CURLOPT_USERAGENT => 'Mozilla Linux U Android en-US AppleWebKit KHTML like Gecko UCBrowser Mobile Safari'
]);
$return = [
'html' => curl_exec($request),
'code' => curl_getinfo($request)['http_code']
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment