PHP methods for obtaining webpage content 1: get content using file_get_contents
Method 2: Use the file_get_contents function to obtain the url in post mode.
'bar');$data = http_build_query($data); $opts = array ('http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data));$ctx = stream_context_create($opts);$html = @file_get_contents($url,'',$ctx);
If you need to transmit cookie data
'Header' => "Content-type: application/x-www-form-urlencoded \ r \ n ".
"Content-Length:". strlen ($ data). "\ r \ n ",
Change
'Header' => "Content-type: application/x-www-form-urlencoded \ r \ n ".
"Content-Length:". strlen ($ data). "\ r \ n ".
"Cookie: cookie1 = c1; cookie2 = c2 \ r \ n ";
You can.
Method 3: use fopen to open the url and get the content.
": Echo" url body: $ result "; fclose ($ fp);?>
Method 4: use fopen to open the url and obtain the content in post mode.
'bar2','foo3'=>'bar3');$data = http_build_query($data); $opts = array ('http' => array ('method' => 'POST','header'=> "Content-type: application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n" ."Content-Length: " . strlen($data) . "\r\n",'content' => $data)); $context = stream_context_create($opts);$html = fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb' ,false, $context);$w=fread($html,1024);echo $w;?>
Method 5: Use the fsockopen function to open the url and get the complete data, including the header and body.
Method 6: Use the fsockopen function to open the url and obtain the complete data in POST mode, including the header and body.
$value)$values[]="$key=".urlencode($value);$data_string=implode("&",$values); // Find out which port is needed - if not given use standard (=80)if(!isset($URL_Info["port"]))$URL_Info["port"]=80; // building POST-request:$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";$request.="Host: ".$URL_Info["host"]."\n";$request.="Referer: $referer\n";$request.="Content-type: application/x-www-form-urlencoded\n";$request.="Content-length: ".strlen($data_string)."\n";$request.="Connection: close\n"; $request.="Cookie: $cookie\n"; $request.="\n";$request.=$data_string."\n"; $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);fputs($fp, $request);while(!feof($fp)) {$result .= fgets($fp, 1024);}fclose($fp); return $result;} ?>
Method 7: Use the curl Library. before using the curl library, you may need to check whether php. ini has enabled the curl extension.