note 39362 added to ref.sockets

From: Date: Mon, 26 Jan 2004 01:26:50 +0000
Subject: note 39362 added to ref.sockets
Groups: php.notes 
Request: Send a blank email to php-notes+get-64183@lists.php.net to get a copy of this message
This function is for retrieving the important request header sections.it takes an address and returns the header from requested data form original server by HTTP request.My Web Site is: http://LonghornXp.50free.org/ if you have any question ,please paln it on my Email: LonghornXp@canada.com <?php function reconizerHeader($address){ error_reporting(E_ALL); $port=getservbyname('www','tcp'); $address_stuff=parse_url($address); $HostIP=gethostbyname($address_stuff['host']); $socket=socket_create(AF_INET,SOCK_STREAM,0); if ($socket<0) echo("socket_create() failed: reason: ".socket_strerror ($socket)."\n"); $connect=socket_connect($socket,$HostIP,80); if($connect<0) echo("socket_connect() failed.\nReason: ($connect)".socket_strerror($connect)."\n"); $input='GET '.$address_stuff['path']." HTTP/1.0\n"; $input.='Host: '.$address_stuff['host']; $input.="\n\n"; socket_write($socket,$input,strlen($input)); $contents=socket_read($socket,2048,PHP_BINARY_READ); preg_match('/Content-Type: [a-zA-Z]+\/?[a-zA-Z]+[; [a-zA-Z]+=[a-zA-Z]+-[0-9]+-[0-9]+]?/',$contents,$array[0]); preg_match('/Content-Length: ([0-9]+)/',$contents,$array[1]); preg_match('/Content-Range: [[a-zA-Z]+ [0-9]*-[0-9]*\/[0-9]*]+/',$contents,$array[2]); preg_match('/Expires: [[a-zA-Z]+, [0-9]+ [a-zA-Z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ [a-zA-Z]+]+/',$contents,$array[3]); preg_match('/Connection: [a-zA-Z]+/',$contents,$array[4]); preg_match('/Accept-Ranges: [a-zA-Z]+/',$contents,$array[5]); preg_match('/Content-MD5: md5-digest/',$contents,$array[6]); preg_match('/Content-[t?T]ype: application\/[a-zA-Z]+/',$output,$array[7]); socket_close($socket); for($i=0,$string='';$i<8;$i++){ for($j=0;$j<count($array[$i]);$j++){ $string.=$array[$i][$j]; if($j==count($array[$i])-1) $string.=' '; } } return $string; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.sockets.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39362 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39362&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39362&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64183) next »