How to Fix: Can not Get Page Source by file_get_contents in PHP

If you use php function “file_get_contents” to get web page source, sometimes this function will not work, however, you can use curl to realize this function, look at source code below:

<?php
 $url = "http://23.com/index.html";
 $ch = curl_init();
 $timeout = 5;
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 //curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);
 $contents = curl_exec($ch);
 curl_close($ch);
 echo $contents;
 ?>