Created
March 18, 2016 18:49
-
-
Save QROkes/99fc55b7e4e4080f0c3c to your computer and use it in GitHub Desktop.
Get HTML source code with cUrl (file_get_contents as fallback)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$urlcontent = qr_loadUrl( 'http://myurl.com' ); | |
function qr_loadUrl( $url ) { | |
if(is_callable( 'curl_init' )) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
} | |
if( empty($data) || !is_callable('curl_init') ) { | |
$opts = array('http'=>array('header' => 'Connection: close')); | |
$context = stream_context_create($opts); | |
$headers = get_headers($url); | |
$httpcode = substr($headers[0], 9, 3); | |
if( $httpcode == '200' ) | |
$data = file_get_contents($url, false, $context); | |
else{ | |
$data = '{"div":"Error ' . $httpcode . ': Invalid Url<br />"}'; | |
} | |
} | |
return $data; | |
} |
Use:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi
i cant read https site by this code.