Curl in drupal 7 fails - php

I am trying to post content to a Drupal 7 site. I don't have administrator privileges so I have to use a module to upload. I am trying to use PHP with curl but it's quite messy:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define("COOKIE_FILE", "/tmp/cookie.txt");
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
$crl = curl_init();
$http_headers = array(
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36', // Any User-Agent will do here
);
$url = "http://mysite.gr/drupal/user/login";
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HEADER, true);
curl_setopt($crl, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
$postdata=array(
"name" => "user",
"pass" => "pass",
"form_id" => "user_login",
"op" => "Submit",
);
// Tell curl we're going to send $postdata as the POST data
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
$result=curl_exec($crl);
$headers = curl_getinfo($crl);
echo curl_exec($crl);
curl_close($crl);
//$file = fopen("/tmp/cookie.txt", 'r');
//fread($file, 100000000);
$crl = curl_init();
$url = "http://mysite.gr/drupal/node/add/simple";
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt ($crl, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crl, CURLOPT_HEADER, true);
$postdata = array(
"title" => "dokimastiki anartisi",
"changed" => "",
"form_id" => "simple_node_form",
"body[und][0][value]" => "hhhhhhh",
"form_id" => "simple-node-form",
"op" => "Save",
);
curl_setopt($crl, CURLOPT_POSTFIELDS, $postdata);
$result=curl_exec($crl);
$headers = curl_getinfo($crl);
echo curl_exec($crl);
?>
It seems that the login succeeds. When it is time to upload I get these errors. The problem is most likely with how the session cookie is stored or the user agent headers. I've searched for hours with no luck for a solution:
HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Wed, 23 Aug 2017 12:49:11 GMT Server: Apache X-Powered-By: PHP/7.0.18 Expires: Sun, 19 Nov 1978 05:00:00 GMT Cache-Control: no-cache, must-revalidate X-Content-Type-Options: nosniff Content-Language: en X-Frame-Options: SAMEORIGIN X-Generator: Drupal 7 (http://drupal.org) Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 X-Backend-Server: standard_backend/web10.hosting.stackcp.net
Anyone knows what I should do? Thanks in advance!

Related

CURL doesn't return transfer

List item
I am trying to read eldorado web page using CURL:
$curl = curl_init();
$url = "https://eldorado.ua/smartfon-samsung-galaxy-a52-8256-gb-black-sm-a525-fzkisek-/p71321565/";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_AUTOREFERER, false);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt(
$curl,
CURLOPT_USERAGENT,
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'
//'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($curl);
var_dump(curl_error($curl));
curl_close($curl);
$content variable has the following contents:
HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: no-cache, no-store
Connection: close
Content-Length: 829
X-Iinfo: 13-324630841-0 0NNN RT(1638095614075 65) q(0 -1 -1 -1) r(0 -1) B12(4,316,0) U18
Strict-Transport-Security: max-age=15768000; includeSubDomains; preload
Set-Cookie: visid_incap_1842303=FMRet2iZRrGNOuu82l7DO/5ao2EAAAAAQUIPAAAAAABVozZ0i7WNRFUDf/QdYAjO; expires=Sun, 27 Nov 2022 10:37:38 GMT; HttpOnly; path=/; Domain=.eldorado.ua; Secure; SameSite=None
Set-Cookie: incap_ses_1339_1842303=OdttRK2/JxoEdGTA1xWVEv5ao2EAAAAAdzZ8EVHb34MWILP16s8cnA==; path=/; Domain=.eldorado.ua; Secure; SameSite=None
<html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta name="viewport" content="initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></head><body style="margin:0px;height:100%"><iframe id="main-iframe" src="/_Incapsula_Resource?SWUDNSAI=31&xinfo=13-324630841-0%200NNN%20RT%281638095614075%2065%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c316%2c0%29%20U18&incident_id=1339000480602535690-1335785097440988173&edet=12&cinfo=04000000&rpinfo=0&cts=pUCYtu4azOH0BoWedolrRwNhF%2fJP8SALxZ2aJzTHaLfVGw1YqkWG3zJRlnNPQgew&mth=GET" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: 1339000480602535690-1335785097440988173</iframe></body></html>
Html body contains only iframe tag, which could not be properly displayed. Does anybody know how to get the whole html body contents?

Why the below PHP cURL code is not POSTing any data?

Can anybody please tell what i am doing wrong in below code ?
I am working on php script to login and scrape data from https://beams.us.yazaki.com/BEAMSLogin/Login.aspx?ReturnUrl=%2FBeams%2FDefault.aspx
I have tried with Below curl code.
<?php
define('USERNAME', 'XXX');
define('PASSWORD', 'XXX');
define('DOMAIN', 'XXX');
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36');
define('COOKIE_FILE', 'cookie.txt');
define('LOGIN_FORM_URL', 'https://beams.us.yazaki.com/BEAMSLogin/Login.aspx?ReturnUrl=%2fBeams%2fDefault.aspx');
define('LOGIN_ACTION_URL', 'https://beams.us.yazaki.com/BEAMSLogin/Login.aspx?ReturnUrl=%2fBeams%2fDefault.aspx');
$postValues = array(
'txtUserName' => USERNAME,
'txtPassword' => PASSWORD,
'lstDomain' => DOMAIN
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, LOGIN_ACTION_URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postValues));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_REFERER, LOGIN_FORM_URL);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_exec($curl);
if(curl_errno($curl)){
throw new Exception(curl_error($curl));
}
curl_setopt($curl, CURLOPT_URL, 'https://beams.us.yazaki.com/BEAMS/SearchAndResults.aspx?topic=component');
curl_setopt($curl, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
echo curl_exec($curl);
?>
I am getting the output like below page.
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.8 *
And the browser is getting redirected to http://localhost/BeamsLogin/AuthenticationSelect.aspx?ReturnUrl=%2fBEAMS%2fSearchAndResults.aspx%3ftopic%3dcomponent&topic=component
I am earnestly waiting for response.
Thanks.
EDIT 1
#Shibon
I think this website doesn't use any csrf token. I am giving HTTP header live content. Please check once.
https://beams.us.yazaki.com/BEAMSLogin/Login.aspx?ReturnURL=%2fBeams%2fDefault.aspx
Host: beams.us.yazaki.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://beams.us.yazaki.com/
Connection: keep-alive
Upgrade-Insecure-Requests: 1
GET: HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 15 Sep 2020 06:19:19 GMT
Content-Length: 3376
Try the bellow code
$ch= curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "-"); //to set session and cookie for the current $ch object
curl_setopt($ch, CURLOPT_URL, LOGIN_ACTION_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postValues));
$resp = curl_exec($ch);
if(!$resp) {
print_r(curl_error($ch));
exit;
}
curl_setopt($curl, CURLOPT_URL, 'https://beams.us.yazaki.com/BEAMS/SearchAndResults.aspx?topic=component');
curl_setopt($ch, CURLOPT_POST, true);
echo curl_exec($ch);
In this have set cookie initially and the used that in all request

I cant reach the url desired with curl

I try curl a website for show it in mine but always I stuck in a white page. I think because it have a redirection to a login form but I dont sure if is the reason because I failed. You can access the url that I use without login.
Here the code
$url = "http://www.faf.es/pnfg/NPcd/NFG_CmpJornada?cod_primaria=1000120&CodCompeticion=16867461&CodGrupo=17910021&CodTemporada=15&CodJornada=26&Sch_Codigo_Delegacion=1&Sch_Tipo_Juego=2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 99999);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec($ch);
curl_close($ch);
htmlentities($output);
The html result:
<html>
<head>
<title></title>
</head>
<body>
<!--
<h1>No se ha aceptado el cookie</h1>
-->
</body>
</html>
Your request url only validate requests which have JSESSIONID cookie. So before you must grab valid cookie:
<?php
$url = "http://www.faf.es/pnfg/NPcd/NFG_CmpJornada?cod_primaria=1000120&CodCompeticion=16867461&CodGrupo=17910021&CodTemporada=15&CodJornada=26&Sch_Codigo_Delegacion=1&Sch_Tipo_Juego=2";
$ch = curl_init();
$useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 99999);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
This gives you three headers for requests:
HTTP/1.1 302 Movido temporalmente
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=648967C5FC907B1225EC61E9A65443E5; Path=/pnfg
Location: http://www.faf.es/pnfg/NLogin
Content-Length: 0 Date: Mon, 22 Jun 2020 19:33:30 GMT
Connection: close
HTTP/1.1 302 Movido temporalmente
Server: Apache-Coyote/1.1
Cache-Control: no-cache
Pragma: no-cache
Set-Cookie: JSESSIONID=9973308FA3AF81BE66C2F8C124671870; Path=/pnfg
Location: http://www.faf.es/pnfg/NLogin?NSess=1
Content-Length: 0 Date: Mon, 22 Jun 2020 19:33:30 GMT
Connection: close
HTTP/1.1 200 OK Server: Apache-Coyote/1.1
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html;charset=ISO-8859-15
Content-Length: 117
Date: Mon, 22 Jun 2020 19:33:30 GMT
Connection: close
We have three header result because we said, request has CURLOPT_FOLLOWLOCATION option. So, we made three request in curl.
I identified, second JSESSIONID cookie value is valid. So, for getting web site information we must use cookie as below:
<?php
$url = "http://www.faf.es/pnfg/NPcd/NFG_CmpJornada?cod_primaria=1000120&CodCompeticion=16867461&CodGrupo=17910021&CodTemporada=15&CodJornada=26&Sch_Codigo_Delegacion=1&Sch_Tipo_Juego=2";
$ch = curl_init();
$useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36';
curl_setopt($ch, CURLOPT_URL, $url);
// Secondary request cookie.
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=9973308FA3AF81BE66C2F8C124671870");
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 99999);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
When web site content comes, do whatever you want.
You should revisit the htmlentities() documentation again; it doesn't do what it appears you believe it does.
In short, htmlentities() returns a string. You aren't capturing or otherwise outputting this string result anywhere. Use echo (or similar) to make sure the result of htmlentities($output) is output to where you expect it.
$url = "http://www.faf.es/pnfg/NPcd/NFG_CmpJornada?cod_primaria=1000120&CodCompeticion=16867461&CodGrupo=17910021&CodTemporada=15&CodJornada=26&Sch_Codigo_Delegacion=1&Sch_Tipo_Juego=2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 99999);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec($ch);
curl_close($ch);
echo htmlentities($output);

PHP CURL returns 403 forbidden response [duplicate]

I am trying to duplicate the Http headers in Php Curl.
My http header is below
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
Now in firexfox http header addon, when i press replay this works correct.But when i do the same via php cur using below code i get error
<?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.A.B.C 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];
?>
The response header for my php curl is
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 ..everything is same as http header addon in firefox.(works even when i am logged out) . But why do i get 403 error in my php curl ? how google detects the curl ?
This should work for you:
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.A.B.C 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);
}
Let me know if this works :)
EDIT: Use http for your plus.google link instead of https. Will that work?
Maybe this will work. I've changed your user agent to the following:
<?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);
}

Php Curl 403 forbidden error

I am trying to duplicate the Http headers in Php Curl.
My http header is below
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
Now in firexfox http header addon, when i press replay this works correct.But when i do the same via php cur using below code i get error
<?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.A.B.C 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];
?>
The response header for my php curl is
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 ..everything is same as http header addon in firefox.(works even when i am logged out) . But why do i get 403 error in my php curl ? how google detects the curl ?
This should work for you:
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.A.B.C 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);
}
Let me know if this works :)
EDIT: Use http for your plus.google link instead of https. Will that work?
Maybe this will work. I've changed your user agent to the following:
<?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);
}

Categories