|
|
|
|
|
для: lgar
(29.06.2007 в 21:36)
| | Ура,заработало
<?php
$link = 'http://php.net';
$result = '';
function rss_get_content ($scheme,$host,$port,$path,$query)
{
global $url,$scheme,$host,$port,$path,$query,$result;
if (empty($host))
{
return false;
}
if ($scheme == 'http')
{
$port = isset($port) ? $port : 80;
}
else
{
$port = isset($port) ? $port : 443;
}
$path = (isset($path) ? $path : '/');
if (function_exists('curl_init'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $scheme."://".$host.$path."?".$query); //Строка,содержащая URL,который должен быть загружен.
curl_setopt($ch, CURLOPT_USERAGENT, 'agent');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, $scheme."://".$host.$path."?".$query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
$result = curl_exec($ch);
curl_close($ch);
if ($result) return $result; else return false;
}
else
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) return false;
else
{
socket_set_timeout($fp, 5);
$headers = "GET $path HTTP/1.1\r\n";
$headers .= "Host: $host\r\n";
$headers .= "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "User-Agent: agent\r\n";
$headers .= "ACCEPT-ENCODING: gzip\r\n\r\n";
$headers .= "Connection: close\r\n\r\n";
}
fwrite($fp, $headers);
$result = '';
while (!feof($fp))
{
$line = fgets($fp, 1024);
$result .= $line;
}
fclose($fp);
return $result;
}
}
$scheme = 'http';
$host = 'php.net';
$port = 80;
$path = '';
$query = '';
rss_get_content($scheme,$host,$port,$path,$query);
print_r($result);
?>
|
Большое спасибо,всем кто помог разобраться | |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 23:25)
| | все,наверно,зависит от области действия переменной.Результат:пустая страница | |
|
|
|
|
|
|
|
для: Trianon
(28.06.2007 в 21:22)
| |
<?php
$link = 'http://php.net';
$result = '';
global $result;
global $url,$scheme,$host,$port,$path,$query;
function rss_get_content ($scheme,$host,$port,$path,$query)
{
if (empty($host))
{
return false;
}
if ($scheme == 'http')
{
$port = isset($port) ? $port : 80;
}
else
{
$port = isset($port) ? $port : 443;
}
$path = (isset($path) ? $path : '/');
if (function_exists('curl_init'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $scheme."://".$host.$path."?".$query); //Строка,содержащая URL,который должен быть загружен.
curl_setopt($ch, CURLOPT_USERAGENT, 'agent');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, $scheme."://".$host.$path."?".$query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
$result = curl_exec($ch);
curl_close($ch);
if ($result) return $result; else return false;
}
else
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) return false;
else
{
socket_set_timeout($fp, 5);
$headers = "GET $path HTTP/1.1\r\n";
$headers .= "Host: $host\r\n";
$headers .= "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "User-Agent: agent\r\n";
$headers .= "ACCEPT-ENCODING: gzip\r\n\r\n";
$headers .= "Connection: close\r\n\r\n";
}
fwrite($fp, $headers);
$result = '';
while (!feof($fp))
{
$line = fgets($fp, 1024);
$result .= $line;
}
fclose($fp);
return $result;
}
}
$scheme = 'http';
$host = 'php.net';
$port = 80;
$path = '';
$query = '';
rss_get_content($scheme,$host,$port,$path,$query);
print_r($result);
?>
|
| |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 21:17)
| | Вы определили функцию. А вызывать её кто будет?
Сама она работать не станет. | |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 00:38)
| |
<?php
$link = 'http://php.net';
function rss_get_content ($link)
{
$url = @parse_url($link);
$scheme = $url['scheme'];
$host = $url['host'];
$port = $url['port'];
$path = $url['path'];
$query = $url['query'];
if (!$url OR empty($host))
{
return false;
}
if ($scheme == 'http')
{
$port = isset($port) ? $port : 80;
}
else
{
$port = isset($port) ? $port : 443;
}
$path = (isset($path) ? $path : '/');
if (function_exists('curl_init'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link); //Строка,содержащая URL,который должен быть загружен.
curl_setopt($ch, CURLOPT_USERAGENT, 'agent');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, $go_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
$result = curl_exec($ch);
curl_close($ch);
if ($result) return $result; else return false;
print_r($result);
}
else
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) return false;
else
{
socket_set_timeout($fp, 5);
$headers = "GET $path HTTP/1.1\r\n";
$headers .= "Host: $host\r\n";
$headers .= "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "User-Agent: agent\r\n";
$headers .= "ACCEPT-ENCODING: gzip\r\n\r\n";
$headers .= "Connection: close\r\n\r\n";
}
fwrite($fp, $headers);
$result = '';
while (!feof($fp))
{
$line = fgets($fp, 1024);
$result .= $line;
}
fclose($fp);
print_r($result);
}
}
?>
|
окончательно я скрипт убил,он даже ошибок не выдаёт-пустая страница :-( | |
|
|
|
|
|
|
|
для: Trianon
(28.06.2007 в 01:40)
| | Вы не подскажите,почему другие не исполняются,как сделать так,чтобы они исполнялись? | |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 00:40)
| | Среди двух процитированных мной строк не было этого оператора. А другие - не исполнялись. | |
|
|
|
|
|
|
|
для: Trianon
(27.06.2007 в 18:41)
| | $communication = false; не определение переменной? | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 19:49)
| | может вместо print_r другую функцию вывода использовать? | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 19:39)
| | добавил print_r(в двух местах)-пустая страница,ничего не работает. | |
|
|
| |
|