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
Related
I'm trying to login to a webpage using PHP and CURL.
The login form on the webpage is the following:
<form action="http://utenti.xxxxx.it/ppnew2_jslogin.phtml" name="login_form" method="post">
<div id="reglink">
<span>Registrati</span>
</div>
<input type="hidden" name="action" value="userlogin">
<label for="login" id="loginlabel">Nome utente:</label>
<input type="text" name="username" value="" id="login">
<label for="password" id="passwordlabel">Password:</label>
<input type="password" name="password" value="" id="password">
<input type="hidden" name="okurl" value="http://www.xxxxx.it/">
<input type="hidden" name="articolo" value="{ARTICOLO}">
<input type="hidden" name="azione" value="Entra">
<input class="header_button" type="submit" name="submit" value=" " alt="invia" title="invia">
</form>
and my php code is made this way:
$postdata = "username=".$username."&password=".$password."&action=".$action."&okurl=".$okurl."&articolo=".$articolo."&azione=".$azione."&submit=".$submit."";
$cookiefile = '/tmp/curl-session';
//initial request with login data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://utenti.xxxxx.it/ppnew2_jslogin.phtml");
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36'); echo curl_error($ch);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
print_r(curl_error($ch));
$result = curl_exec($ch);
// Then, once we have the cookie, let's use it in the next request:
//another request preserving the session
curl_setopt($ch, CURLOPT_URL, "www.xxxxx.it");
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
//curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookiefile );
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$result1 = curl_exec($ch);
curl_close($ch);
echo $result;
I want to log in and then keep the session for the next request, but I can't figure out why the log in is not working. I send all the variables listed in the form but nothing...
Do you have any idea?
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'));
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 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>
I trying to log on to my bank using curl. It all works great until it comes to the cookies (which are set by javascript). This is the form i am trying to send (the credentials are fake):
<form method="post" action="https://www.icabanken.se/Secure/Login/LoginVerify.aspx">
<input type="hidden" name="pnr" value="8502191714" />
<input type="hidden" name="JSEnabled" value="1" />
<input type="hidden" name="OBAS" value="" />
<input type="hidden" name="refurl" value="" />
<input type="hidden" name="refurlrequiressigning" value="False" />
<input type="password" class="typetext" name="Password" id="PasswordSimple" maxlength="4" value="1111" />
<input class="button-image button-small" type="submit" id="LoginSimplifiedButton" value="Logga in" />
</form>
Using following PHP / CURL code:
enter codssde here
$post_data['pnr'] = '8502191714';
$post_data['password'] = '1111';
$post_data['JSEnabled'] = '1';
$post_data['OBAS'] ='';
$post_data['refurlrequiressigning'] = '';
$post_data['refurl'] = '';
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_array = implode ('&', $post_items);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_CERTINFO, 1);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 1000000);
//COOKIES
$Cookiefile='C:\wamp\www\Project1\gcookies.txt';
curl_setopt($ch, CURLOPT_COOKIEFILE, $Cookiefile);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $Cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
curl_setopt($ch, CURLOPT_URL,'https://www.icabanken.se/Secure/Login/LoginVerify.aspx');
$data = curl_exec($ch);
echo $data;
The response i get is "Your browser is not supporting cookies". It there any neat solution to get around this?
My advice would be to use something like Fiddler2:
http://www.fiddler2.com/fiddler2/
Log into your bank normally and Fiddler will log everything (You need to enable https decoding, otherwise it only see's http traffic)
From these logs, you can see the raw header information and raw cookie contents. Then use this information to replicate the login in cURL.