İ want login instagram with php curl. When I try to login below code is always changing So i must get this input value:
<input type="hidden" name="csrfmiddlewaretoken" value="uCbmYHcQLe18VAvVFXbfyPcS5kXtCuuE">
my curl code is:
<?php
$url = "https://www.instagram.com/accounts/login/?force_classic_login";
$values = "csrfmiddlewaretoken=" + $key + "&username=myusername&password=mypassword";
$key = "";
//foreach input name csrfmiddlewaretoken = $key
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $values);
$veri = curl_exec($curl);
curl_close($curl);
echo $veri;
?>
Try this:
$veri = curl_exec($curl); // That $veri contains the curl response into it
$data = json_decode($veri, true); // Convert the response into an array
now the $data is an array and you can access the values from this array by using its indexes.
Man, explode the response content with the separator <input then get on array result your data.
Do something like this:
$result = explode('<input type="hidden" name="csrfmiddlewaretoken" value="', $file_content);
$result = explode('">', $result[1] );
$input_value = $result[0];
$input_value = $result[0];
i hope this help
Related
I have tried everything I know and I have failed totally to parse this multi dimensional array so that I can get the "symbol" keys and corresponding values of "contractType" , but I can't seem to get it.
The array is generated here: https://fapi.binance.com/fapi/v1/exchangeInfo
So I am doing the following:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$results = [];
foreach ($data['symbols'] as $info) {
$results[] = $info['symbol'];
}
print_r($results);
I tried a foreach loop, for loop, tried various offsets eg. $data[0]['symbols']..
to $data[9]['symbols'] etc. but can't seem to get the correct array offset.
10000"}],"symbols":[{"symbol":"BTCUSDT","pair":"BTCUSDT","contractType":"PERPETUAL","deliveryDate
I'm trying to loop through the "symbols" offset within this main array, and get 1. the "symbol" 2. its corresponding "contractType"
Ty..
It doesn't work because the CURL result is in JSON.
You got to convert it to an array before you can loop through it.
$data = json_decode($data, true);
It looks like you need to convert the JSON response into an array before you loop over it.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$results = [];
$data = json_decode($data);
$i = 0;
foreach ($data->symbols as $info) {
$results[$i]['symbol'] = $info->symbol;
$results[$i]['contractType'] = $info->contractType;
$i++;
}
print_r($results);
Yes. Thankyou.. (didn't understand answer properly.)
$url = 'https://fapi.binance.com/fapi/v1/exchangeInfo';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, true);
$results = [];
$symbols = $data['symbols'];
$i = 0;
foreach ($symbols as $info) {
$results[$i]['symbol'] = $info['symbol'];
$results[$i]['contractType'] = $info['contractType'];
$i++;
}
print_r($results);
Much appreciated, ty..
Here is my code :
$query = "SELECT first_name, surname, email FROM app2";
$result = mysql_query($query) or die(mysql_error());
$url = "https://test.com?"; // Where you want to post data
while($row = mysql_fetch_array($result)) {
$input = "";
foreach($row as $key => $value) $input .= $key . '=' . urlencode($value) . '&';
$input = rtrim($input, '& ');
$ch = curl_init(); // Initiate cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true); // Tell cURL you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS, $input); // Define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output in string format
$output = curl_exec ($ch); // Execute
curl_close ($ch); // Close cURL handle
var_dump($output); // Show output
}
The problem is the data ($input) come out like this :
0=Lucky&first_name=Lucky&1=Dube&surname=Dube
It should be like this :
first_name=Lucky&surname=Dube
No need to build your query on your own. First off, just use _assoc()* function flavor, then use http_build_query on that row array batch, then feed it. It will construct the query string for you. No need to append each element with & with your foreach. Rough example:
$url = "https://test.com"; // Where you want to post data
while($row = mysql_fetch_assoc($result)) {
$input = http_build_query($row);
$ch = curl_init(); // Initiate cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true); // Tell cURL you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS, $input); // Define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output in string format
$output = curl_exec ($ch); // Execute
curl_close ($ch); // Close cURL handle
}
Try changing
while($row = mysql_fetch_array($result)) {
with
while($row = mysql_fetch_assoc($result)) {
mysql_fetch_assoc returns only the associative array.
Im printing on the $url the $_REQUEST and $_POST variables.. only showing an empty array..
what am I doing wrong?
function redirect_post($url, $data, $headers = null)
{
// Url Encoding Data
$encdata = array();
foreach ($data as $key => $value) {
$encdata[$key] = urlencode($value);
}
//url-ify the data for the POST
$encdata_string = http_build_query($encdata);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_POST,count($encdata));
curl_setopt($ch,CURLOPT_POSTFIELDS,$encdata_string);
//execute post
$result = curl_exec($ch);
echo $result;
die;
}
Try using the following code. It looks like you need to put your URL in the curl_init and then send the $data over using the curl_setopt to send the array.
$userIp = array('userIp'=>$_SERVER['REMOTE_ADDR']);
$url = 'http://xxx.xxx.xxx.xxx/somedirectory/somescript.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $userIp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
I'm trying to store the titles in an array and extract the long cmcontinue string from the below url.
http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:1980_births&format=json
my current code:
$url = 'http://en.wikipedia.org/w/api.php?
action=query&list=categorymembers&cmtitle=Category:'.$cat.'&format=json';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "asdf");
$c = curl_exec($ch);
$json = json_decode($c);
$array = $json->{'query'}->{'categorymembers'}->{'title'};
try adding second paremeter of json_decode, like:
$json = json_decode($c, true);
And get cmcontinue value as:
echo $json["query-continue"]["categorymembers"]["cmcontinue"];
For titles:
$titles = array();
foreach($json["query"]["categorymembers"] as $vals) {
array_push($titles, $vals["title"]);
}
echo "<pre>"; print_r($titles);
This is one of my first curls code, so it can have mistakes
I'm trying to be able to make calls to form/:id/submissions
https://www.formstack.com/developers/api/resources/submission#form/:id/submission_GET
If I load:
https://www.formstack.com/api/v2/form/1311091/submission.json?oauth_token=abc&min_time=2012-09-01%2000:01:01&max_time=2012-10-27%2000:01:01
If works great.
If I try this code:
<?php
$host = 'https://www.formstack.com/api/v2/';
// TODO this should manage dinamics values or build an action in every method.
$action = 'form/1311091/submission.json';
$url = $host . $action;
// TODO this values will arrive like an array with values
$postData['oauth_token']= 'abc';
$postData['min_time'] ='2012-09-01 00:01:01';
$postData['max_time'] ='2012-10-27 00:01:01';
// TODO make a method with this action
function getElements($postData)
{
$elements = array();
foreach ($postData as $name=>$value) {
$elements[] = "{$name}=".urlencode($value);
}
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $elements);
$result = curl_exec($curl) ;
curl_close($curl);
var_dump($result);
?>
You'll need to set:
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
As an option before curl_exec() if you wish to get data back.
CURLOPT_RETURNTRANSFER: TRUE to return the transfer as a string of the
return value of curl_exec() instead of outputting it out directly.
Also, why are you trying to send POST data via a GET request?
CURLOPT_POSTFIELDS: The full data to post in a HTTP "POST" operation.
Also, for debugging, you should check out:
echo curl_error ( $curl );
This works for me:
<?php
$host = 'https://www.formstack.com/api/v2/';
$action = 'form/1311091/submission.json';
$url = $host . $action;
$postData = array();
$postData['oauth_token']= 'REPLACE_WITH_TOKEN';
$postData['min_time'] ='2012-09-01 00:01:01';
$postData['max_time'] ='2012-10-27 00:01:01';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
?>