Public feed #600073

Unnamed

public php v1 · immutable
Raw Edit
·published 2007-07-02 16:41 UTC
rendered paste body
function my_get_headers($url) {	       $url_info=parse_url($url);       if (isset($url_info['scheme']) && $url_info['scheme'] == 'https') {           $port = 443;           @$fp=fsockopen('ssl://'.$url_info['host'], $port, $errno, $errstr, 10);       } else {           $port = isset($url_info['port']) ? $url_info['port'] : 80;           @$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 10);       }       if($fp) {           stream_set_timeout($fp, 10);           $head = "HEAD ".@$url_info['path']."?".@$url_info['query'];           $head .= " HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";           fputs($fp, $head);           while(!feof($fp)) {               if($header=trim(fgets($fp, 1024))) {                        $sc_pos = strpos( $header, ':' );                        if( $sc_pos === false ) {                           $headers['status'] = $header;                        } else {                            $label = substr( $header, 0, $sc_pos );                            $value = substr( $header, $sc_pos+1 );                            $headers[strtolower($label)] = trim($value);                        }               }           }           return $headers;       }       else {           return false;       }   }        $urls = explode("\n",$_GET['urls']);    	if(is_array($urls)) {	    	    foreach($urls as $url) {				$data[] = my_get_headers($url);			    }	    	    print_r($data);	    	}        //    if(strpos($headers['status'],'200 OK') !== false || strpos($headers['status'],'405 MethodNotAllowed') !== false || strpos($headers['status'],'400 Bad Request') !== false) {//	//	echo 'true';//	//    } elseif($headers['status'] == 'HTTP/1.0 301 Moved Permanently') {//	//	echo 'moved:'.$headers['location'];//	//    } else {//	//	echo 'false';//	//	print_r($headers);//	//    }?><form action="" method="get">  <textarea name="urls"></textarea>  <input type="submit" /></form>