PHP Curl Response - php

I am currently working with an API for a little project of mine that will only accept POST requests, however no matter what I seem to do I cannot get a response out of it, I have tried echoing the response, I have tried returning it, I have tried using print_r and nothing works. Can someone tell me what I am doing wrong?
<?php
$applicationPass = $_GET['appPass'];
$email = $_GET['email'];
$password = $_GET['password'];
if ($applicationPass == "abc123"){
//
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_URL => 'http://api.minergate.com/1.0/auth/login/',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'email' => urlencode($_GET['email']),
'password' => urlencode($_GET['password'])
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo $resp;
//
}else{
die();
}
?>
Here is my updated code, I get a little bit of a different response with their new API that took forever to find.
<?php
$applicationPass = $_GET['appPass'];
$email = $_GET['email'];
$password = $_GET['password'];
if ($applicationPass == "abc123"){
//
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_URL => 'https://minergate.com/api/2.2/auth/login',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0',
CURLOPT_CUSTOMREQUEST => 'POST',
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'email: ' . $email,
'password: ' . $password
)),
CURLOPT_POSTFIELDS => array(
'email' => urlencode($email),
'password' => urlencode($password)
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo $resp;
//
}else{
die();
}
?>

Related

PHP - How do i put the X-CSRF-TOKEN in the headers?

How do I put the $token or x-csrf-token to headers?
The curl post works when I put x-csrf-token in the headers manually.
What should I do to put the $token or x-csrf-token automaticly to headers?
When I make a new curl post that gets token and when I put the token automatic on the headers the response of the curl is 404 bad request
This is my script:
$Thing = $_GET['Thing'];
$username = $_GET['username'];
$password = $_GET['password'];
$login = array(
"cvalue" => $username,
"ctype" => "Username",
"password" => $password,
"captchaToken" => $Thing,
"captchaProvider" => "PROVIDER_ARKOSE_LABS"
);
$curl = curl_init('https://auth.roblox.com/v2/login'); // There are many links you can login from
curl_setopt_array($curl,array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_POSTFIELDS => json_encode($login),
CURLOPT_HEADER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'Accept: application/json, text/plain, */*',
'X-CSRF-TOKEN: '
),
CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
));
$response = curl_exec($curl);
$size = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
curl_close($curl);
#$response1 = explode(" ", $response);
#$cookie = $response1[10];
#$search = ".ROBLOSECURITY=";
#$cookie1 = str_replace($search, '', $cookie);
$headers = substr($response,0,$size);
$array = explode("\n",$headers);
foreach($array as $data){
if(strpos($data,'csrf')){
$info = explode(' ',$data);
break;
}
}
$csrf = $info[1];
$token = $csrf;
print_r($token);
print_r($response);
There isn't a way to automatically attach custom headers to all CURL requests. The best way is to wrap your CURL code inside a function and pass the desired CSRF token as a parameter. Here's a demo:
function curl_call(array $params, string $csrf_token)
{
... curl code here...
'X-CSRF-TOKEN: '. $csrf_token,
... remaining curl code here...
}
Then when you want to make a CURL request, you may call the function like this:
curl_call(['url' => '...', etc], 'csrf token string here');

getting a bad request response when doing a curl call

I am receiving a bad request from the server when I make a curl request. Not sure where I went wrong, but it looks like that some of the CURLOPT options are incorrect. Do you have any idea what needs to be changed?
This is the code:
$url = "https://order.pizzahut.com/site/ajax/find_nearby";
$ch = curl_init($url);
$useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'; // Setting useragent of a popular browser
$header = array("Accept: application/json, text/plain, */*");
$options = [
CURLOPT_USERAGENT => $useragent,
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR => "cookie.txt",
CURLOPT_REFERER =>"https://www.google.com",
CURLOPT_CUSTOMREQUEST=>"POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER =>$header
];
curl_setopt_array($ch, $options);
loadPage("AK", "ANCHORAGE",$ch);
function loadPage($abbreviation,$city,$ch){
global $conn;
$city = strtolower($city);
$near = "$city,"."$abbreviation";
echo $near;
$postData = [
'occasion' => "C",
'near' => "$near",
'zip' => "$near",
'address' => "",
'dine_in' => false,
'store_limit' =>"10",
'locator' =>true
];
$payload = json_encode($postData);
# Convert the post data array to URL encoded string
// $postDataStr = http_build_query($postData);
echo $payload;
$options[CURLOPT_POSTFIELDS] = $payload;
$html = curl_exec($ch);
echo $html;
}
yes you are right, its post request only issue with header it requires valid Cookie in header. I just copied Cookie from browser and paste in header and its works. So the solution is:
loadPage("AK", "ANCHORAGE");
function loadPage($abbreviation,$city){
$city = strtolower($city);
$near = "$city,"."$abbreviation";
$postData = [
'occasion' => "C",
'near' => "$near",
'zip' => "$near",
'address' => "",
'dine_in' => false,
'store_limit' =>"10",
'locator' =>true
];
$url = "https://order.pizzahut.com/site/ajax/find_nearby";
$ch = curl_init($url);
$useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'; // Setting useragent of a popular browser
$header = array(
"Accept: application/json, text/plain, */*",
"Cookie: failover_checked=1; PHPpoolSSL=!4maklee1+k5+tBLWWPR8rI/3M2NcIXVsgM+5XMIVRK/fJJleEnP4hyVoopcRquvCAs/7CbLq/Vfd0cc=; TS011d6839=01166f2bd0e693828ed3fb37eef086402c5626aca6908460b9722b154cb51f244b1dd882278db1bb1f9ac97a3f2d3617b12e7c7b5c; www-origin=yeti-HR-HARYANA-; www-origin-reset=1; exp_last_visit=1143192473; optimizelyEndUserId=oeu1458555784471r0.9519811202417545; _gat_UA-34361514-1=1; QOSESSID=6ohua5ugd55mjupf0p6k32uia6; _dc_gtm_UA-34361514-1=1; exp_last_activity=1458560242; exp_tracker=a%3A5%3A%7Bi%3A0%3Bs%3A12%3A%22site%2Flocator%22%3Bi%3A1%3Bs%3A4%3A%22home%22%3Bi%3A2%3Bs%3A5%3A%22index%22%3Bi%3A3%3Bs%3A23%3A%22site%2Fajax%2Fclear_session%22%3Bi%3A4%3Bs%3A38%3A%22site%2Fajax%2Fcoupons%2FremoveNationalCoupon%22%3B%7D; TS01bded03=01166f2bd034b629d99e25089af83586e4bf2347f7b1f70b91972e835cfd37e486120c510cfabe2bd9856390632a8276d8250ae05869b06cc1d6a7bc77ee826c8b208bc7361686c0b1cbd41a8530948d8fa923b0b3; TS0118ed69=01166f2bd0c9a8c11fd75a87aad59a90e93a811cbea110792544f73601f99f85ef0de952c0bb1c1706650ace601420df60560355a33fa2ecea9f8f89e1fdd807c0f5717ab8fe2b84c6305f1add271e312787310fa30c484c0174c988835bcea2ced9db5fcf; optimizelySegments=%7B%22209642986%22%3A%22referral%22%2C%22209669694%22%3A%22gc%22%2C%22209692476%22%3A%22false%22%2C%22209740042%22%3A%22none%22%2C%22307825635%22%3A%22true%22%7D; optimizelyBuckets=%7B%7D; _ga=GA1.2.700288496.1458555787; optimizelyPendingLogEvents=%5B%5D"
);
$options = [
CURLOPT_USERAGENT => $useragent,
CURLOPT_COOKIESESSION => true,
// CURLOPT_COOKIEJAR => "cookie.txt",
// CURLOPT_REFERER =>"https://www.google.com",
CURLOPT_POST=>true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER =>$header
];
// $payload = json_encode($postData);
$options[CURLOPT_POSTFIELDS] = http_build_query($postData);
curl_setopt_array($ch, $options);
$html = curl_exec($ch);
echo $html;
}
Output
{"success":true,"response":[{"address":"118 E 6th Ave","city":"Anchorage","state":"AK","zip":"99501","country":"US","phone":"(907)337-2323","lat":61.216325,"long":-149.882477,"distance":0.81,"StoreNumber":"011168","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"100 E Benson Blvd","city":"Anchorage","state":"AK","zip":"99503","country":"US","phone":"(907)337-2323","lat":61.193863,"long":-149.882482,"distance":1.82,"StoreNumber":"011169","OnlineOrdering":true,"WingStreet":true,"Buffet":true,"DineIn":true},{"address":"2205 E Tudor Rd #39","city":"Anchorage","state":"AK","zip":"99507","country":"US","phone":"(907)743-9828","lat":61.1811,"long":-149.840628,"distance":2.59,"StoreNumber":"014640","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"341 Boniface Pkwy, Unit G","city":"Anchorage","state":"AK","zip":"99504","country":"US","phone":"(907)337-2323","lat":61.220935,"long":-149.777626,"distance":2.7,"StoreNumber":"008615","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"3727 Spenard Highway","city":"Anchorage","state":"AK","zip":"99517","country":"US","phone":"(907)337-2323","lat":61.186142,"long":-149.914382,"distance":2.86,"StoreNumber":"010576","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"1921 W Dimond Blvd Ste 112","city":"Anchorage","state":"AK","zip":"99515","country":"US","phone":"(907)337-2323","lat":61.139149,"long":-149.915007,"distance":5.74,"StoreNumber":"009150","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"12870 Old Seward Hwy","city":"Anchorage","state":"AK","zip":"99515","country":"US","phone":"(907)337-2323","lat":61.103643,"long":-149.858735,"distance":7.87,"StoreNumber":"010684","OnlineOrdering":true,"WingStreet":true,"Buffet":false,"DineIn":false},{"address":"11740 Old Glenn Hwy","city":"Eagle River","state":"AK","zip":"99577","country":"US","phone":"(907)337-2323","lat":61.326675,"long":-149.571538,"distance":12.15,"StoreNumber":"008181","OnlineOrdering":true,"WingStreet":true,"Buffet":true,"DineIn":true},{"address":"851 E Parks Hwy","city":"Wasilla","state":"AK","zip":"99654","country":"US","phone":"(907)373-6600","lat":61.58137,"long":-149.429086,"distance":28.87,"StoreNumber":"010324","OnlineOrdering":true,"WingStreet":true,"Buffet":true,"DineIn":true}],"store_info":{"011168":{"address":"118 E 6th Ave","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99501,"phone":"(907) 337-2323","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"10:00AM","delivery_close":"11:30PM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:47:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-20 22:49:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"011169":{"address":"100 E Benson Blvd","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99503,"phone":"(907) 337-2323","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"11:30AM","delivery_close":"11:00PM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-08 21:12:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-20 23:09:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"014640":{"address":"2205 E Tudor Rd #39","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99507,"phone":"(907) 743-9828","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"10:00AM","delivery_close":"12:00AM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 03:09:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-21 03:07:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"008615":{"address":"341 Boniface Pkwy, Unit G","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99504,"phone":"(907) 337-2323","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"10:00AM","delivery_close":"12:00AM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 02:40:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-20 23:40:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"010576":{"address":"3727 Spenard Highway","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99517,"phone":"(907) 743-9877","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"12:00PM","delivery_close":"12:00AM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:47:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-20 19:57:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"009150":{"address":"1921 W Dimond Blvd Ste 112","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99515,"phone":"(907) 337-2323","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"10:00AM","delivery_close":"12:00AM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:48:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-21 01:34:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"010684":{"address":"12870 Old Seward Hwy","city":"Anchorage","state":"AK","state_name":"Alaska","zip":99515,"phone":"(907) 337-2323","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"12:00PM","delivery_close":"11:30PM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:53:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-21 01:53:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"008181":{"address":"11740 Old Glenn Hwy","city":"Eagle River","state":"AK","state_name":"Alaska","zip":99577,"phone":"(907) 694-1086","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"10:00AM","delivery_close":"12:00AM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:31:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-20 22:31:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35},"010324":{"address":"851 E Parks Hwy","city":"Wasilla","state":"AK","state_name":"Alaska","zip":99654,"phone":"(907) 373-6600","status":"","carryout_open":false,"carryout_close":false,"carryout_future_order":true,"delivery_open":"12:00PM","delivery_close":"11:00PM","delivery_future_order":true,"closure_reason":"","onlineStatus":"online","firstTimeDiscount":false,"currentlyOpen":false,"deliveryAvailable":false,"carryoutAvailable":false,"acceptFutureOrders":true,"landmark":null,"futuredelivery":true,"futurecarryout":true,"pizzaEvoTestStore":true,"offlineStatusMsg":null,"showDeliveryTime":"Y","promiseTimeDel":35,"promiseTimeLastUpdateDel":{"date":"2016-03-21 01:12:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeDelStale":true,"showCarryoutTime":"Y","promiseTimeCo":15,"promiseTimeLastUpdateCo":{"date":"2016-03-21 01:12:00","timezone_type":3,"timezone":"America\/Chicago"},"promiseTimeCoStale":true,"promiseTime":35}},"closed_event":"011168","dimensions":{"exp":"b327ba0a88f0d185c2648ce42a7543c6","usertype":"Guest","storeid":"national","requesttime":"06:39:25"},"ga_tracking":{"ga_label":"Bing Success","errors":null},"user_location":{"city":"Haryana","state":"HR","state_name":null}}
First you are setting curl options with $options without CURLOPT_POSTFILEDS and then you set $options CURLOPT_POSTFIELDS within loadPage function, but those new options are not passed to curl handler by curl_setopt_array();
use curl_setopt_array just after
$options[CURLOPT_POSTFIELDS] = $payload;

Server not responding using Curl POST Request

I am using this code to get the contents of a post request url using php curl
Code looks as below:
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'barcode' => 'CP021325078TR',
'security_code' => $capcha2
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo "<pre>";
var_dump($resp);
echo "</pre>";
The result doesn’t seem to return anything at all.
What is wrong with this code?
Try this:
$url = 'http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php';
$postvals = array(
'barcode' => 'CP021325078TR',
'security_code' => $capcha2
);
$resp = Request($url,$postvals);
echo "<pre>"; var_dump($resp); exit;
...
function Request($url,$params=array()){
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true
);
if(!empty($params)){
$curlOpts[CURLOPT_POST] = true;
$curlOpts[CURLOPT_POSTFIELDS] = $params;
}
curl_setopt_array($ch,$curlOpts);
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch); exit;
}
curl_close($ch);
return $answer;
}
EDIT:
I tested this and got:
Could not resolve host: www1.ptt.gov.tr
So make sure you're calling the right endpoint.
Actually you need to set this variable
$captcha2
To use it here -
'security_code' => $capcha2

PHP solution to JSON responses and parameters

I feel each step i take this one 5 more walls come up its fun but also frustrating.
So I'm trying to login to a website through cURL and after a lot of head scratching and the use of firefox developer tools I saw that my browser was responding in JSON. I honestly dont know anything about JSON but i feel like if i get through this I'll be in the clear.
So the question is how do i emulate these JSON responses with cURL? do i just copy and paste what they are in an array? Do i include this array in each http requests or do i do them all seperately.
Here is the JSON code if you guys want to see it.
__jsonp1__([{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","advice":{"reconnect":"retry","interval":0,"timeout":600000}}]);
__jsonp2__([{"id":"3","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/connect","successful":true,"advice":{"reconnect":"retry","interval":0,"timeout":600000}},{"id":"2","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/subscribe","successful":true,"subscription":"/user/11585628"}]);
__jsonp3__([{"id":"4","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/connect","successful":true,"advice":{"reconnect":"retry","interval":0,"timeout":600000}},{"channel":"/user/11585628","data":{"type":"subscribe"},"clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","id":"5","authenticated":true}]);
_jsonp4__([{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"uiqqkp0vf66rl0mlc8281ufknaw1qkcriu1","advice":{"reconnect":"retry","interval":0,"timeout":600000}}]);
here is my code I was trying somethings so thats why it make look a little weird
<?php
$ckfile =' __utma=173730677.1410450142.1370766442.1370882903.1370893342.8; __utmz=173730677.1370893342.8.6.utmcsr=web.groupme.com|utmccn=(referral)|utmcmd=referral|utmcct=/groups; __utma=64278953.892306882..1370882931.1370893339.9; __utmz=64278953.1370882931.8.4.utmcsr=groupme.com|utmccn=(referral)|utmcmd=referral|utmcct=/signin; _g=%3D%3D--772097f0c6a077ac0f904c981ba5523ddffef3d5; __utmc=64278953; __utmc=173730677; __utmb=64278953.1.10.1370893339; __utmb=173730677.2.10.1370893342';
$postfields = '{"username":"#gmail.com","password":"somepass","app_id":"groupme.com","grant_type":"password"}';
$postfields2 ='{"group":{"name":"test","memberships":[]}}';
$custom = 'X-Access-Token: CEbhaIkkKTc9dtVMpxyc2IZOfnzEoh5w4UTzsVSb';
$ch2 = curl_init();
$ch3 = curl_init();
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://web.groupme.com/#access_token=some token',
CURLOPT_COOKIE=> $ckfile,
CURLOPT_USERAGENT =>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0',
CURLOPT_REFERER => 'https://groupme.com/signin',
CURLOPT_RETURNTRANSFER => true,
//CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => array('Host: web.groupme.com','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')
)
);
curl_setopt_array(
$ch2,
array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://web.groupme.com/#access_token=some token',
CURLOPT_COOKIE=> $ckfile,
CURLOPT_USERAGENT =>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0',
CURLOPT_REFERER => 'https://groupme.com/signin',
CURLOPT_RETURNTRANSFER => true,
//CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => array('Host: web.groupme.com','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','Content-Type=text/html;charset=utf-8','Server=thin 1.3.1 codename Triple Espresso','Strict-Transport-Security=max-age=31536000','X-Frame-Options=sameorigin','x-xss-protection=1; mode=block','Content-Length=24275')
)
);
$response = curl_exec($ch2);
//curl_close($ch);
echo '<pre>';
print_r($response);
echo '</pre>'
?>

Logging Into AliBaba.com programmatically

I am trying to figure out how to login to the website https://login.alibaba.com using PHP and CURL. I am using the code below but it does not seem to be working. How would you recommend I login to this site automatically?
My current code:
<?
$cookie = "cookie.txt";
// set global curl options
$curloptions = array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
CURLOPT_TIMEOUT => 60,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_REFERER => 'http://www.alibaba.com'
);
// set userinfo
$username = 'xxxxxxxxxxx';
$password = 'xxxxxxxxxxx';
// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);
// make a dummy request to generate a session
curl_http_request('https://login.alibaba.com', $curloptions);
// login
curl_http_request('https://login.alibaba.com',
array(
CURLOPT_POSTFIELDS => 'xloginPassport=' . $username . '&xloginPassword=' . $password . '&noCsrfToken=&xloginCheckToken=&rememberme=&runatm=',
CURLOPT_POST => TRUE
), $curloptions
);
//example request
echo curl_http_request('https://login.alibaba.com',
array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE
), $curloptions
);
function curl_http_request ($url, $moreoptions = array(), $options = array())
{
foreach ($moreoptions as $k => $v) $options[$k] = $v;
$handle = curl_init($url);
curl_setopt_array($handle, $options);
ob_start();
$buffer = curl_exec($handle);
ob_end_clean();
curl_close($handle);
return $buffer;
}
?>
They are using some token generation method on login, so unless you know how to generate the same, just use their web login.
Here's a typical login request looks like:
https://login.alibaba.com/xman/xlogin.js?pd=alibaba&pageFrom=standardlogin&u_token=Bf0323500b707423d50c96aae931e204b&xloginPassport=andreaswongg70&xloginPassword=10fd852ff6603865cf632b59d935e56b&dmtrack_pageid=ca1b1fe2cdcc700d4f66917813628a849a71fcca49

Categories