Created
January 22, 2017 03:15
-
-
Save gracefullight/eb74deb9a3693c00732ec46ca152a9f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* [getData 외부파일을 GET 방식으로 읽기] | |
* @param [string] $str [url] | |
* @param [array] $data [parameters] | |
* @return [string] [내용] | |
*/ | |
function getData($str, $data){ | |
$url = parse_url($str); | |
switch(strtoupper($url['scheme'])){ | |
case 'HTTP': | |
if (!isset($url['port'])){ | |
$url['port'] = 80; | |
} | |
break; | |
case 'HTTPS': | |
$url['ssl'] = 'ssl://'; | |
if (!isset($url['port'])){ | |
$url['port'] = 443; | |
} | |
break; | |
} | |
$fp = @fsockopen($url['ssl'].$url['host'], $url['port'], $errno, $errstr, 10); | |
if ($fp){ | |
fwrite($fp, "GET $url[path]?".http_build_query($data)." HTTP/1.0\r\nHost: $url[host]\r\n"); | |
while (!feof($fp)) { | |
$out .= fread($fp, 1024); | |
} | |
fclose($fp); | |
$out = explode("\r\n\r\n",$out); | |
array_shift($out); | |
$out = implode("",$out); | |
} | |
return $out; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment