I'm tryng to read the source using fopen() but, it is not working with this code! (Not work in webhosting account or localhost) any idea of , why such thing occurs!!! <?php $fh = fopen("http://www.pornhub.com", "r") or die('Failed to open ***** !'); $fullstring; while(!feof($fh)) { $output = htmlspecialchars(fgets($fh, 1024)); $fullstring = $fullstring."".$output; } echo "**hi**"; echo "<br/>"; echo $fullstring; ?> Code (markup): (Note: if the site url is a new one for example: redtube.com - then it works fine) How to resolve this? Thanks
Try the CURL method (this function was designed to replace file_get_content but allowing users to simply rename their function to file_get_content_curl()) function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } PHP: Above is probably going to be your best bet since most webservers opting for security, is going to disable fopen being able to remotely open files, as well as disabling the file_get_contents function.
yh kbless..... this works. but it displays the whole website. Is there a way to get the source-code from that!... In the return $data; section i want to get the source-code and display (echo) that on the screen other than the site. function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } Code (markup): thankx