【发布时间】:2018-11-25 14:46:32
【问题描述】:
所以,我一直在寻找使用 php 的页面标题。研究了 5 秒,我在这里找到了答案:
function get_title($url){
$str = file_get_contents($url);
if(strlen($str)>0){
$str = trim(preg_replace('/\s+/', ' ', $str));
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title);
return $title[1];
}
}
但我需要通过 Tor 代理,所以 5 秒研究这个网站和你的智慧,我发现:
$aContext = array(
'http' => array(
'proxy' => 'proxy:port',
'request_fulluri' => true,
)
);
$cxContext = stream_context_create($aContext);
综合起来,我做到了:
$aContext = array(
'http' => array(
'proxy' => '127.0.0.1:9150',
'request_fulluri' => true,
)
);
$cxContext = stream_context_create($aContext);
function get_title($url){
global $cxContext;
$str = file_get_contents($url, False, $cxContext);
if(strlen($str)>0){
$str = trim(preg_replace('/\s+/', ' ', $str));
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title);
return $title[1];
}
}
echo get_title('http://' . $theonionurl);
但是,这行不通。日志显示:
PHP 警告:file_get_contents(http://the_onion_address_to_check.onion):无法打开流:第 44 行 /var/www/html/mychecker.php 中的连接被拒绝,引用者:http://my_onion_address.onion/mychecker.php
我把端口改成了9050,还是不行。
我做错了什么???
(显然,我检查了,要检查的 url 是有效的,并且可以通过 Tor 浏览器访问)
【问题讨论】:
标签: php linux file-get-contents tor