Возможно ли записать получаемые заголовки в переменную ?
это выводит. А у меня запрос в Классе.
curl_setopt($ch, CURLOPT_HEADER, true);
И вообще возможно ли это ?
function getHeaders($ch, $str)
{
echo $str . '<br>';
return strlen($str);
}
$ch = curl_init('http://phpforum.su');
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1' );
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "getHeaders");
$result = curl_exec($ch); // выполняем запрос curl
curl_close($ch);
HTTP/1.1 200 OKили мы не про то?
Server: nginx/1.1.19
Date: Wed, 03 May 2017 22:13:20 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.2.17
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Wed, 03 May 2017 21:03:36 GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: CookieIp=*.*.*.*
Set-Cookie: session_id=******************************; path=/
class PickpointВ ответ тишина .
{
public $headers_return;
public function _curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this,'getHeaders') );
.....
}
private function getHeaders($ch, $str){
$this->headers_return = $str;
//echo $this->headers_return;
return strlen($str);
}
public function Headers_return(){
return $this->headers_return;
}
}
$curl= new Pickpoint();
....
echo $curl->Headers_return();
class Pickpoint
{
public $headers_return;
private function getHeaders($ch, $str){
// echo $str . '<br>';
// $this->headers_return[] = $str;
return strlen($str);
}
public function Headers_return(){
return $this->headers_return;
}
public function _curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1' );
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_NOBODY, 1);
curl_setopt ($ch, CURLOPT_HEADERFUNCTION, "getHeaders" );
$result = curl_exec($ch); // выполняем запрос curl
curl_close($ch);
}
}
$curl= new Pickpoint();
echo $curl->_curl( 'http://phpforum.su' );