note 47344 deleted from function.fopen by cmb

From: Date: Sun, 09 Feb 2020 08:07:59 +0000
Subject: note 47344 deleted from function.fopen by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214032@lists.php.net to get a copy of this message
Note Submitter: Thomas Candrian tc_ at gmx dot ch ---- With this it isn't possible to get data from another port than 80 (and 443) - at least for me. Because of that I've made this function who gets data from every port you want using HTTP: <?php; function getcontent($server, $port, $file) { $cont = ""; $ip = gethostbyname($server); $fp = fsockopen($ip, $port); if (!$fp) { return "Unknown"; } else { $com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n"; fputs($fp, $com); while (!feof($fp)) { $cont .= fread($fp, 500); } fclose($fp); $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4); return $cont; } } echo getcontent("www.myhost.com", "81", "/")); ?> Works fine for me. Had to do this especially for a shoutcast server, which only delivered the HTML-file if the user-agent was given.

« previous php.notes (#214032) next »