note 80435 deleted from function.file-get-contents by salathe

From: Date: Mon, 21 Sep 2020 14:37:57 +0000
Subject: note 80435 deleted from function.file-get-contents by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215231@lists.php.net to get a copy of this message
Note Submitter: php [spat] hm2k.org ---- I decided to make a similar function to this, called file_post_contents, it uses POST instead of GET to call, kinda handy... <?php function file_post_contents($url,$headers=false) { $url = parse_url($url); if (!isset($url['port'])) { if ($url['scheme'] == 'http') { $url['port']=80; } elseif ($url['scheme'] == 'https') { $url['port']=443; } } $url['query']=isset($url['query'])?$url['query']:''; $url['protocol']=$url['scheme'].'://'; $eol="\r\n"; $headers = "POST ".$url['protocol'].$url['host'].$url['path']." HTTP/1.0".$eol. "Host: ".$url['host'].$eol. "Referer: ".$url['protocol'].$url['host'].$url['path'].$eol. "Content-Type: application/x-www-form-urlencoded".$eol. "Content-Length: ".strlen($url['query']).$eol. $eol.$url['query']; $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30); if($fp) { fputs($fp, $headers); $result = ''; while(!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); if (!$headers) { //removes headers $pattern="/^.*\r\n\r\n/s"; $result=preg_replace($pattern,'',$result); } return $result; } } ?>

« previous php.notes (#215231) next »