note 63843 added to function.file-get-contents

From: Date: Sat, 01 Apr 2006 18:49:52 +0000
Subject: note 63843 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-107134@lists.php.net to get a copy of this message
I wrote a function that can get the contents of a url through foskcopen() <?php /* * @desc get the contents of a url through fsockopen() * @param IP * @param Port number * @param file * @param timeout * @param add headers to result? * @return the contents with or without headers */ function sock_get_contents($ip, $port, $file, $timeout, $header = false) { $request = "GET ".$file." HTTP\1.0\r\n\r\n"; $return = ''; $sock = fsockopen($ip, $port, $err_no, $err_str, $timeout); if(is_resource($sock)) { fputs($sock, $request); if($header == false) { $line = ""; while(!($line == "\r\n")) { $line = fgets($sock, 128); if(preg_match("#Location\: (.*?)\\r\\n#si", $line, $matches)) { return sock_get_contents($ip, $port, "/".$matches[1], $timeout, $header); } } // strip out the header } while ($buffer = fgets($sock, 4096)) { $return .= $buffer; } fclose($sock); return $return; } else { return false; } } ?> ---- Server IP: 194.109.193.119 Probable Submitter: 80.61.237.46 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php Edit -- http://master.php.net/note/edit/63843 Del: integrated -- http://master.php.net/note/delete/63843/integrated Del: useless -- http://master.php.net/note/delete/63843/useless Del: bad code -- http://master.php.net/note/delete/63843/bad+code Del: spam -- http://master.php.net/note/delete/63843/spam Del: non-english -- http://master.php.net/note/delete/63843/non-english Del: in docs -- http://master.php.net/note/delete/63843/in+docs Del: other reasons-- http://master.php.net/note/delete/63843 Reject -- http://master.php.net/note/reject/63843 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107134) next »