$url='http://softgroups.com'; $agent="SoftGroups Header Reader (http://softgroups.com)"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); curl_setopt($ch, CURLOPT_HEADER, 1); $buffer=curl_exec($ch); curl_close($ch); echo $buffer; ?> I want onlt to get the header from the server what;'s wrong!? this scrit return me the whole page, lol
try this: <?php $url='http://softgroups.com'; $agent="SoftGroups Header Reader (http://softgroups.com)"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 1); $buffer = curl_exec($ch); $curl_info = curl_getinfo($ch); curl_close($ch); $header_size = $curl_info[header_size]; $header = substr($buffer, 0, $header_size); echo $header; ?> PHP: $curl_info = curl_getinfo($ch); to capture the curl request info $curl_info[header_size] will contain the curl request header size $header = substr($buffer, 0, $header_size); to only get the header by the header size finally $header will contain only the header information.
You may need to set the NOBODY flag to get only the headers. curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); PHP: