Php Curl 403 запрещенная ошибка

Я пытаюсь дублировать заголовки Http в Php Curl.

Мой заголовок http ниже

Host: plus.google.com Content-Type: application/x-www-form-urlencoded; Cookie:NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=xxxxxxxxxxxxxx 

Теперь в firexfox http header addon, когда я нажимаю replay, это работает правильно. Но когда я делаю то же самое через php cur, используя ниже код, я получаю ошибку

 <?php function poster($url,$fields_string){ $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Content-Type:application/x-www-form-urlencoded','Cookie: NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=ZIMOP9lJ_E8SLdkL/A32W20hPpwgd5Kg1J')); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.ABC Safari/525.13"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch,CURLOPT_POST, count($fields_string)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); $last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); return array($result,$last); curl_close($ch); } $url = "https://plus.google.com/_/sharebox/post/?source=frameless&spam=56&hl=en&ozv=es_oz_20130602.13_p3&f.sid=-834406139015290241&_reqid=358119&rt=j"; $string = 'f.req=%5B%22%22%2C%22oz%3A105057244581488239720.13f0ec465f5.0%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B337%2C336%2C335%2C0%5D%2C%22http%3A%2F%2Fadjmpw.com%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%7B%2240154698%22%3A%5B%22http%3A%2F%2Fadjmpw.com%22%2Cnull%2C%22DOMAIN%20ERROR%22%2C%22%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu898b%5Cu3064%5Cu304b%5Cu308a%5Cu307e%5Cu305b%5Cu3093.%20%5Cu8003%5Cu3048%5Cu3089%5Cu308c%5Cu308b%5Cu539f%5Cu56e0.%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu307e%5Cu3060%5Cu884c%5Cu308f%5Cu308c%5Cu3066%5Cu3044%5Cu306a%5Cu3044%5Cu3002%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu307e%5Cu3060%5Cu53cd%5Cu6620%5Cu3055%5Cu308c%5Cu3066%5Cu3044%5Cu306a%5Cu3044%5Cu3002(%5Cu53cd%5Cu6620%5Cu306b%5Cu306f%5Cu6570%5Cu6642%5Cu9593%5Cuff5e24%5Cu6642%5Cu9593%5Cu304b%5Cu304b%5Cu308b%5Cu3053%5Cu3068%5Cu304c%5Cu3042%5Cu308a%5Cu307e%5Cu3059)%3B%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu30fbDNS%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu8aa4%5Cu3063%5Cu3066%5Cu3044%5Cu308b%5Cu3002%20%5Cu30a2%5Cu30ab%5Cu30a6%5Cu30f3%5Cu30c8%5Cu304c%5Cu5b58%5Cu5728%5Cu3057%5Cu306a%5Cu3044%5Cu3001%5Cu5951%5Cu7d04%5Cu304c%5Cu7d42%5Cu4e86%5Cu3057%5Cu3066%5Cu3044%5Cu308b%5Cu3001%5Cu524a%5Cu9664%5Cu3055%5Cu308c%5Cu3066%5Cu3044%5Cu308b%5Cu3002%22%2Cnull%2Cnull%2C%22%2F%2Fs2.googleusercontent.com%2Fs2%2Ffavicons%3Fdomain%3Dadjmpw.com%22%2C%5B%5D%2Cnull%2Cnull%2C%5B%5D%2C%22adjmpw.com%22%2Cnull%2C%5B%5D%2C%5B%5D%2C%5B%5D%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D%7D%5D%2Cnull%2C%5B%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%2Cnull%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22!A0Kqty2yd13VXUSIQmFRwsHOTgIAAACcUgAAABMqAOOd_e40c9ZGEcvCbLFeO4xd-bERNZUdpPVB47P7EAX_SOsuScB1gj-i9hJCjwcEohHLhq9-1lnTIG6wDZoXbyksjLzUxuna6V4JfCOO_eohj7MQnsKiVuhKHcHKrOqP8WDZ8dgmUIFNVubfBPNemcuPOd8eahSf-JP9-6XMqnKdNIlTWLYqQvQWfohWhqmeu6K_tFBRDoUweLCSttIlehy66khLWOebSYf8cuLx_VQRH4Mdq-P1Cc4JlKrBwwoQPW66-Tpbb11OhHDSd7uh7S-Md7NMwkJSVzfGnWZZ3ZCjc6Cgzg%22%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D&at=AObGSAh9hx7LgvgMum-4aVedQIfEJa8FgA%3A1370342318767&'; echo "<pre>"; $game = poster($url,$string); echo $game[0]; ?> 

Заголовок ответа для моего php curl

 HTTP/1.1 403 Forbidden Content-Type: application/json; charset=UTF-8 Content-Disposition: attachment; filename="response.txt" Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Tue, 04 Jun 2013 10:46:03 GMT Set-Cookie: NID=67=U68qmM7sSUNdgJY64JIEltRkmhYS7l9mTZXX7GL2Z0BpnYBgZL2FsVnjpAYUvToyBFzGY7SLGAS5Ko0K-N61I4VV7HTvIlZvX9ARxSxKR_KQtfjHDbqZ3pK_y-X7V-Oe;Domain=.google.com;Path=/;Expires=Wed, 04-Dec-2013 10:46:03 GMT;HttpOnly P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info." X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked 

My post content, cookie, post url .. все то же, что и http header addon в firefox. (Работает, даже когда я вышел из системы). Но почему я получаю ошибку 403 в моем php curl? как Google обнаруживает завиток?

Это должно сработать для вас:

 function poster($url,$fields_string){ $ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.ABC Safari/525.13'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_USERAGENT, $ua); curl_setopt($ch, CURLOPT_COOKIE, 'NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=ZIMOP9lJ_E8SLdkL/A32W20hPpwgd5Kg1J'); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); $last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); return array($result,$last); } 

Дайте мне знать, если это работает 🙂

EDIT: используйте http для вашей ссылки plus.google вместо https. Будет ли это работать?


Возможно, это сработает. Я изменил ваш пользовательский агент на следующее:

 <?php // ADD THIS $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; function poster($url,$fields_string){ $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Content-Type:application/x-www-form-urlencoded','Cookie: NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=ZIMOP9lJ_E8SLdkL/A32W20hPpwgd5Kg1J')); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); //CHANGE THIS curl_setopt($ch, CURLOPT_USERAGENT, $agent; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch,CURLOPT_POST, count($fields_string)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); $last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); return array($result,$last); curl_close($ch); }