php curl - send post values (with header: location) - php

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);
?>

Related

get response/result after submitting file to url

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>

PHP while loop curl IFisset error

Here is my script
$id=$row['user_id'];
if (isset($_GET['trea'])){
$ch = curl_init(); // Initialise a cURL handle
// Setting proxy option for cURL
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '$proxy_ip');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($ch, CURLOPT_URL, $final);
$results = curl_exec($ch); // Execute a cURL request
curl_close($ch);
echo $results;
}
?>
<form action='admin.php' method='get'>
<input type=submit name="trea" value="<?php echo $id ?>">
Now if i click on submit button on my page.It sends CURL request to all the rows instead of that particular row.so i tried to change this
if (isset($_GET['trea'])){
to
if (isset($_GET['$id'])){
and
<input type=submit name="trea" value="<?php echo $id ?>">
to
<input type=submit name="$id" value="<?php echo $id ?>">
And when i try to submit the button.It does nothing.What am i doing wrong? i want to run CURL request on that particular row when i click on submit button of that row

ask about send image failed using telegram API?

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);
?>

curl sending information POST method

I am trying to pass data from an HTML form POST using curl, does anyone know how to do this?
My code: (dtda.php)
<?php
// HTTP authentication
$url = "http://siteapi.com.br:9988/api";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "Teste:123456");
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
My second code HTML: (sending.html)
<form name="myform" id="myform" action="http://endereco.com.br/dtda.php" method="post" >
<input type="text" name="op" value="event"/>
<input type="text" name="seq" value="45" />
<input type="text" name="type" value="nexttrack" />
<input type="text" name="priority" value="1" />
<input type="submit" style="padding-left:10px; padding-right:10px" class="button compact" onclick="javascript:openlive()" value="Ativar agendamento" /><p></form> <br /><br />
</form>
As I pass the form data to the "endereco.com.br/dtda.php" ?
try
$url = "http://siteapi.com.br:9988/api";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(array('yourData' => $data)));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
If you want to forward the posted data to another URL, you can add it like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));

login to a website and after login upload file using curl

I want to login to a site and then upload a file using curl
I have successfully logged into website, now i want to upload a file using the same curl connection. Is it possible?
My code so far:
$id ='myusername';
$password ='mypassword';
$cookie_file_path = "cookie.txt";
$agent =$_SERVER['HTTP_USER_AGENT'];
$getfile='http://archive.org/download/TestVideo_935/Backntro.mp4';
$getfile=file_get_contents($getfile);
$POSTFIELDS = array(
'username'=>$id,
'password'=>$password,
'uploadfile'=>'#'.$getfile
);
//post info for login
$LOGINURL = "http://****.com/**/;
$reffer = "http://*****.com/***/";//path to upload file
//in my case I want to upload video as this site is video site
$ch = curl_init ($LOGINURL);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($session, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data",
));
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt ($ch, CURLOPT_COOKIEFILE,$cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$info = curl_getinfo($ch);
$result = curl_exec ($ch);
print_r($info);
print_r($result);
any help will be greatly appreciated !! Thanks very much !
<form method="post" action="userfiles" enctype="multipart/form-data">
<div class="formrow">
<label for="uploadfile">File</label>
<input type="file" name="uploadfile" id="uploadfile" />
<span id="note_uploadfile"></span></div>
<div class="formrow"><label for="uploadname">
Name</label><input type="text" name="uploadname" id="uploadname" /> <span
<div class="submitrow"><label></label>
</form>

Categories