I have the following script:
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_URL, 'http://4pda.ru/forum/index.php?act=idx');
curl_setopt($curl, CURLOPT_HEADER, true);
$headers = array();
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Host: 4pda.ru';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0';
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$cookie_path = "./cookies.txt";
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_path);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$result = curl_exec($curl);
var_dump(curl_getinfo($curl,CURLINFO_HEADER_OUT)); //problem one
curl_close($curl);
var_dump($result);
I have two problems. First, PHP Curl does not set headers. It sends only these headers:
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0
Host: 4pda.ru
Accept: */*
You can see that the php set headers incorrectly. The second problem is that the server returns the following content:
HTTP/1.1 403 Forbidden
Server: nginx
Date: Wed, 26 Jun 2013 14:26:18 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Keep-Alive: timeout=20
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>
Although, I expect to get a html of page.
It is surprising that this script works fine on my home server (windows), and on my previous server. I think that my problems are due to incorrectly configure a new server. But I could be wrong.
I would be glad to any advice. Regards, Denis.
Update. Thanks Ma Chuan, the first problem is solved.