|
|
|
| Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /home/a1zos/public_html/lev/1.php on line 48
<?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 : '/');
$communication = false;
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);
if ($result !== false)
{
$communication = true; //1
}
}
}
if (!$communication)
{
$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: ocrExpress\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);
}
?>
|
1)Не могу понять в чём дело,почему-то не работает часть с curl(curl установлен и в рабочем состоянии),скрипт переключается на fsockopen и выдает ошибку-Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /home/a1zos/public_html/lev/1.php on line 48,ошибка в адресе,меняю скрипт ввожу прямо в fsockopen нужный урл,без всяких переменных,выдает bad_request.
2)Комментирую всё что связано с fsockopen,никаких ошибок не выдает, пустая страница.
3)На переменные,$host,$port(47 строчка)-Notice: C:\1.php line 47 - Undefined variable: host
4)почему не работает $communication?
5)Проверял на локалхосте,и на хосте.Ошибки теже.
6)Во время написание кое-что переделал,так что могут ещё ошибки возникнуть,(sorry). | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 18:22)
| | Первый исполняющийся оператор у Вас - $link = 'http://php.net';
Второй - if (!$communication)
Переменная не определена.
А значит считается нулевой (ложной). | |
|
|
|
|
|
|
|
для: Trianon
(27.06.2007 в 18:41)
| | как переменную определить? | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 18:56)
| | исходя из этого вопроса задам встречные
1. зачем вы тогда ставили условие
2. что вы ожидаете от этой переменной | |
|
|
|
|
|
|
|
для: bronenos
(27.06.2007 в 19:08)
| | если установлен curl выполнить нужные команды,записать $communication=true,тогда обращаться к серверу при помощи fsockopen не придется и этот блок мы упускаем,если curl нет,то следовательно выполняется fsockopen | |
|
|
|
|
|
|
|
для: Trianon
(27.06.2007 в 18:41)
| | $communication = false; не определение переменной? | |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 00:40)
| | Среди двух процитированных мной строк не было этого оператора. А другие - не исполнялись. | |
|
|
|
|
|
|
|
для: Trianon
(28.06.2007 в 01:40)
| | Вы не подскажите,почему другие не исполняются,как сделать так,чтобы они исполнялись? | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 18:22)
| |
<?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;
}
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);
}
}
?>
|
вроде работает,еще раз проверю. | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 19:39)
| | добавил print_r(в двух местах)-пустая страница,ничего не работает. | |
|
|
|
|
|
|
|
для: lgar
(27.06.2007 в 19:49)
| | может вместо print_r другую функцию вывода использовать? | |
|
|
|
|
|
|
|
для: 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);
}
}
?>
|
окончательно я скрипт убил,он даже ошибок не выдаёт-пустая страница :-( | |
|
|
|
|
|
|
|
для: lgar
(28.06.2007 в 21:17)
| | Вы определили функцию. А вызывать её кто будет?
Сама она работать не станет. | |
|
|
|
|
|
|
|
для: 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 в 23:25)
| | все,наверно,зависит от области действия переменной.Результат:пустая страница | |
|
|
|
|
|
|
|
для: 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);
?>
|
Большое спасибо,всем кто помог разобраться | |
|
|
|
|