note 50357 deleted from function.fsockopen by danbrown

From: Date: Mon, 18 May 2009 01:56:03 +0000
Subject: note 50357 deleted from function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155612@lists.php.net to get a copy of this message
Note Submitter: redvader at yandex dot ru ---- here are some fixes to code by edwin at bitstorm dot org they might seem silly, but still useful in some cases <?php function fetchURL( $url ) { $url_parsed = parse_url($url); $host = $url_parsed["host"]; $port = $url_parsed["port"]; if ($port==0) $port = 80; $path = $url_parsed["path"]; //if url is http://example.com without final "/" //I was getting a 400 error if (empty($path)) $path="/"; //redirection if url is in wrong format if (empty($host)): $host="www.somesite.com"; $path="/404.shtml"; endif; if ($url_parsed["query"] != "") $path .= "?".$url_parsed["query"]; $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"; $fp = fsockopen($host, $port, $errno, $errstr, 30); fwrite($fp, $out); $body = false; while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); return $in; } fetchURL($address); ?>

« previous php.notes (#155612) next »