Read the source of a webpage

Discussion in 'PHP' started by zerandib, Oct 27, 2009.

  1. #1
    i want to get the source code of this webpage:
    http://www.pornhub.com/view_video.php?viewkey=5984790cc93d68a4f181

    I hv tried like this;
    
    <?php
    $fh = fopen("http://www.pornhub.com/view_video.php?viewkey=5984790cc93d68a4f181", "r") or die("***CANNOT READ***");
    
    $fullstring;
    while(!feof($fh))
    {
        $output = htmlspecialchars(fgets($fh, 1024));
    	#echo ("$output");
    	$fullstring = $fullstring."".$output; 
    }
    
    echo $fullstring;
    ?>
    
    PHP:

    But it says it is not possible to read the file! :confused:
    here the demo of this code: http://getvidz.info/demo.php -> NOT working

    But , this works fine... when tried using this :
    http://demo.efoxt.com/4zerandibbuy/

    How to do such a thing! ... i just want to read the source;
    if possible.... pls provide sample code
     
    zerandib, Oct 27, 2009 IP
  2. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mate use CURL...

    here is a little function I wrote for u..
    
    function get_content($url)  
    { 
    	$ch = curl_init();  
    	curl_setopt ($ch, CURLOPT_URL, $url);  
    	curl_setopt ($ch, CURLOPT_HEADER, 1); 
    	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');  
    
    	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    	ob_start();  
    	curl_exec ($ch);  
    	curl_close ($ch);  
    	$string = ob_get_contents();  
    	ob_end_clean();  
    	return $string;      
    }
    
    //usage sample
    $url = "http://www.pornhub.com/view_video.php?viewkey=5984790cc93d68a4f181";
    $mydata = get_content($url); 
    echo $mydata; 
    PHP:
    btw the code is not tested
     
    xenon2010, Oct 27, 2009 IP
  3. zerandib

    zerandib Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    :) thx
    works fine
     
    zerandib, Oct 27, 2009 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Mate, use CURLOPT_RETURNTRANSFER rather than output buffering.
     
    nico_swd, Oct 27, 2009 IP
  5. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #5
    nabil_kadimi, Oct 27, 2009 IP
  6. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    glad that I helped :D
     
    xenon2010, Oct 27, 2009 IP
  7. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #7
    only source? why not file_get_contents?
     
    astrazone, Oct 27, 2009 IP