i can't inject the cookie in page2, Some tips pls.
With this method i load page1 with catcha what containing the cookie
and write it to cookie.txt :
define('COOKIE', './cookie.txt');
define('CAPTCHA', './captcha.png');
function saveCaptcha() {
$header = array('Content-Type: image/png');
$ch = curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_COOKIESESSION, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, COOKIE);
curl_setopt($ch,CURLOPT_URL,'http://example.com/captcha/securimage_show.php');
curl_setopt($ch,CURLOPT_PROXY,'127.0.0.1:8118');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);
$fileContents = curl_exec($ch);
curl_close($ch);
$newImg = imagecreatefromstring($fileContents);
return imagepng($newImg, "CAPTCHA",9);
}
$fr = filesize(COOKIE);
echo COOKIE . ': ' . $fr . ' bytes';
if ($fr <= 50) saveCaptcha();
Cookie successful saved and writed to cookie.txt, now we past captcha in form:
<form action="index.php" method="post">
<input type="hidden" name="p" value="login" />
<div class="line">
<label>Captcha</label>
<img src="CAPTCHA" border="0" />
</div>
<div class="line">
<label> </label>
<input type="text" name="captcha" value=""/>
</div>
<div class="line">
<label> </label>
<input type="submit" value="Login" />
</div>
</form>
Now we extract the captcha with $_POST and load page2 with our cookie.txt:
//extract data from the post
extract($_POST);
//set POST variables
$url = 'http://example.com/index.php';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch,CURLOPT_COOKIESESSION, true);
curl_setopt($ch,CURLOPT_PROXY, '127.0.0.1:8118');
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POSTFIELDS, 'p=login&user=myuser&pass=123qwe&captcha='.$_POST['captcha'].'&submit=Login');
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch,CURLOPT_REFERER, 'http://example.com/');
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
$fa = fopen(COOKIE, 'w');
#fwrite(COOKIE,'');
fclose($fa);
Page2 is loaded but without cookie. Some tips pls maybe you will saw the issue(( THanks.
Related
I have watched some tutorials on how to pass a variable from a form to a php file, and cannot get anything to happen when I click the submit button. I am making a page that searches the Clash of Clans API to display the clan searched.
I just need to have the form submit the clan tag to the php script.
Here is my code. The file is a php file and the form action is blank because the php is in the file.
<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
$clantag = $_POST['var'];
}
$token = Token Goes Here;
$url = "https://api.clashofclans.com/v1/clans/" . urlencode($clantag);
$ch = curl_init($url);
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
curl_close($ch);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="button" name="submit" value="Submit">
</form>
You should replace the type of the button from "button" to "submit"
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="submit" name="submit" value="Submit">
</form>
I'm trying to submit a file to a REST API url and need to get the response/result from this process. I'm trying to send it to another php and display the result but nothing. If it could display in the same php page then even better. How am i suppose to do that?
<?php
session_start();
// Start the session
$responseURL = "http://my-site.com/responseform.php";
$url = 'https://api-to-validate-file.com/api/validate';
$header = array('Content-Type: multipart/form-data','Authorization: apikey=0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f');
$fields = array('filename' => '#' . $_FILES['filename']['tmp_name'][0]);
$token = 'NfxoS9oGjA6MiArPtwg4aR3Cp4ygAbNA2uv6Gg4m';
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_HTTPHEADER, $header);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_POST, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, $fields);
curl_setopt($resource, CURLOPT_COOKIE, 'apiToken=' . $token);
$result = json_decode(curl_exec($resource));
///echo 'The body of the response is ' . $result;
curl_close($resource);
?>
<form method="post" action="index.php" enctype="multipart/form-data">
<input name="filename" type="file" />
<input type="submit" value="Upload" />
<input type="hidden" name="RespURL" value="<?= $responseURL ?>"><br>
</form>
now i'm work with telegram API. i want send an image with this API but my code doesnt work, when i run it, i have a blank response.
here is my code :
<?php
$comment= $_POST['tag'];
$url = 'https://api.telegram.org/botMY_BOT_ID/sendPhoto';
try {
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data"));
curl_setopt($curl_connection, CURLOPT_URL, $url);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, http_build_query(array('chat_id'=>'chatid','photo' => "#"."maldini.jpg")));
//curl_setopt($curl_connection, CURLOPT_INFILESIZE, filesize("path/to/maldini.jpg"));
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
//Data are stored in $data
$data = curl_exec($curl_connection);
curl_close($curl_connection);
} catch(Exception $e) {
return $e->getMessage();
}
?>
but, when i try send image with just html, i works perfectly. here is my html code :
<form method="POST" action="https://api.telegram.org/botMY_BOT_ID/sendPhoto" enctype="multipart/form-data">
<label>
<span>chat_id :</span>
<input id="chat_id" type="text" name="chat_id" value="chat_id" />
</label>
<label>
<span>caption :</span>
<input id="caption" type="text" name="caption"/>
</label>
<label>
<span>photo</span>
<input id="photo" type="file" name="photo" />
</label>
<label>
<span> </span>
<input type="submit" class="button" value="sendPhoto" />
</label>
</form>
whats wrong??? any help would be appreciate, thanks in advance :)
just need to pass chat_id with the url, try this code
<?php
$url = "https://api.telegram.org/bot<bot_id>/sendPhoto?chat_id=".$chat_id ;
$post_fields = array('chat_id' => $chat_id,'photo'=> "/path/to/image.png");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$output = curl_exec($ch);
echo "<pre>"; print_r($output);
?>
is the first time that I compile with a curl: i'm trying to use it to send post values with header. i did many tests, but probably I mistake something because I in output don't see my post vars.
form page:
<html>
<form action="analize.php" method="post">
<input type="text" name="people" value="" />
<input type="submit" value="Send" />
</form>
</html>
analize.php:
<?php
$url = 'test.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_exec($ch);
curl_close($ch);
header('Location: ' . $url);
exit;
?>
test.php:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'analize.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_exec($ch);
$post = curl_getinfo($ch);
curl_close($ch);
var_dump($post);
?>
I'm using php and curl and I have some problems with a form with enctype=multipart/form-data.
the form in the remote web page:
<form method="post" enctype="multipart/form-data" action="/account/login" id="login">
<label for="username">Username</label><input name="username" id="username"><br>
<label for="password">Password</label><input name="password" id="password" type="password"><br>
<input type="checkbox" name="keeplogged" id="keeplogged" value="on"><label for="keeplogged">Remember me</label><br>
<input type="submit" name="submit" value="Submit" />
</form>
the post data (from Firefox):
POSTDATA =-----------------------------24464570528145
Content-Disposition: form-data; name="username"
fakeuser
-----------------------------24464570528145
Content-Disposition: form-data; name="password"
fakepass
-----------------------------24464570528145
Content-Disposition: form-data; name="keeplogged"
on
-----------------------------24464570528145
Content-Disposition: form-data; name="submit"
Submit
-----------------------------24464570528145--
and I'm trying to do a login with curl:
function login($ref)
{
// Identify the URL:
$url = 'http://www.fakeSite.com/account/login';
$dt = array();
$dt['username'] = 'fakeUser';
$dt['password'] = 'fakePass';
$dt['keeplogged'] = 'on';
$dt['submit'] = 'Submit';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dt);
$result = curl_exec($curl);
if(curl_errno($curl))//If there is any error
{
echo 'Curl error: ' . curl_error($curl);
exit();
}
curl_close($curl);
return $result;
}
but the result is nothing! No result, no errors, nothing! Anyone have any idea?
PS: I have tried to pass the postfields formatted like the one from Firefox, but this didn't solve the problem.
I got some problems with API using enctype=multipart/form-data (Proxmox VE).
Try to add your POST datas using a string instead of an array (with http_build_query) :
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($dt));