Új hozzászólás Aktív témák
-
fsockopen() függvénnyel:
(a függvények - kicsit átírva - a php.net-ről származnak)
<?php
/*
* A választ adja vissza fejlécek nélkül.
*/
function parseHttpResponse($content=null) {
if (empty($content)) { return false; }
// split into array, headers and content.
$hunks = explode("\r\n\r\n",trim($content));
if (!is_array($hunks) or count($hunks) < 2) {
return false;
}
$header = $hunks[count($hunks) - 2];
$body = $hunks[count($hunks) - 1];
$headers = explode("\r\n",$header);
unset($hunks);
unset($header);
if (!validateHttpResponse($headers)) { return false; }
if (in_array('Transfer-Encoding: chunked', $headers)) {
return trim(unchunkHttpResponse($body));
} else {
return trim($body);
}
}
/*
* Sikerült-e?
*/
function validateHttpResponse($headers=null) {
if (!is_array($headers) or count($headers) < 1) { return false; }
switch(trim(strtolower($headers[0]))) {
case 'http/1.0 100 ok':
case 'http/1.0 200 ok':
case 'http/1.1 100 ok':
case 'http/1.1 200 ok':
return true;
break;
}
return false;
}
/*
* ha darabolt az eredmény, akkor össze kell rakni, különben hülye számok és betűk jelennek meg a tartalomban
*/
function unchunkHttpResponse($str=null) {
if (!is_string($str) or strlen($str) < 1) { return false; }
$eol = "\r\n";
$add = strlen($eol);
$tmp = $str;
$str = '';
do {
$tmp = ltrim($tmp);
$pos = strpos($tmp, $eol);
if ($pos === false) { return false; }
$len = hexdec(substr($tmp,0,$pos));
if (!is_numeric($len) or $len < 0) { return false; }
$str .= substr($tmp, ($pos + $add), $len);
$tmp = substr($tmp, ($len + $pos + $add));
$check = trim($tmp);
} while(!empty($check));
unset($tmp);
return $str;
}
$host = "eu.wowarmory.com";
$file = "/guild-info.xml?r=Nordrassil&gn=Solidarity";
$user_agent_string = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1';
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
die("$errstr ($errno)<br />\n");
} else {
$out = "GET $file HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "User-Agent: $user_agent_string \r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$content = '';
while (!feof($fp)) {
$content .= fgets($fp);
}
fclose($fp);
}
echo parseHttpResponse($content);
Új hozzászólás Aktív témák
- Akciós Windows 10 pro + Office 2019 professional plus csomag AZONNALI SZÁLLÍTÁS
- BESZÁMÍTÁS! MSI B450M R5 3600 16GB DDR4 512GB SSD GTX 1080 8GB Rampage SHIVA ADATA 600W
- Fém, összecsukható és kihúzható fotó állvány eladó
- Csere-Beszámítás!AMD Asztali számítógép PC Játékra! R5 5600/ RX 6700XT 12GB / 16GB DDR4 / 500GB SSD
- Apple iPhone 13 128GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest