php - curl authorization to remote server doesnt work - php

Please help, i spent 3 days now for solving of this problem.
I try get authorization and show after page like "/index.php?page=xml", but I get only login page, some cookies saved to local server.
Here is PHP curl code:
<?php
$login = 'XX';
$password = 'XX';
$site = 'http://site';
$cookies = dirname(__FILE__) . '/cookies.txt';
$automatic = curl_init();
curl_setopt($automatic, CURLOPT_USERAGENT, $user_agent);
curl_setopt($automatic, CURLOPT_REFERER, "http://google.com/");
curl_setopt($automatic, CURLOPT_TIMEOUT, 10);
curl_setopt($automatic, CURLOPT_URL, $site . '/index.php?page=index');
curl_setopt($automatic, CURLOPT_RETURNTRANSFER, true);
curl_setopt($automatic, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($automatic, CURLOPT_POST, true);
curl_setopt($automatic, CURLOPT_POSTFIELDS, "user.auth.login=$login&user.auth.pass=$password");
curl_setopt($automatic, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($automatic, CURLOPT_COOKIEJAR, $cookies);
curl_exec($automatic);
curl_setopt($automatic, CURLOPT_URL, $site. '/index.php?page=xml');
$demo = curl_exec($automatic);
curl_close($automatic);
echo $demo;
?>
Cookies.txt:
site FALSE / FALSE 1429273488 def.sess.number 2a86dcf7d2a896f323fb2931337efe60
The site form:
<form name=enterform action="/index.php?page=index" method=post>
<table border=0 cellspacing=0 cellpadding=2 width=740>
<tr>
<td valign=bottom bgcolor=#01568D width=80>
<input type=input maxlength=32 size=9 class="logindata" name="user.auth.login" value="" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);"><br>
<input type=password maxlength=32 size=9 class="logindata" name="user.auth.pass" onKeyDown="return TrapKeyDown(event);" onKeyPress="return TrapKeyPress(event);">
</td>
</tr>
<tr>
<td bgcolor=#01568D height=40 colspan=2 align=right valign=bottom><font class="startbuttons">LOGIN</font> </td>
</tr>
</table>
</form>
Whagt I do wrong?

Related

PHP cURL login doesn't work

I am trying to create a remote login to one website using mine. The users will need to enter their username and password on my site, and if they are registered to my website, their login credentials will be sent to another website and a page will be retrieved.
I am stuck at sending the users' data to the original site. The original site's viewsource is this..
<form method=post>
<input type="hidden" name="action" value="logon">
<table border=0>
<tr>
<td>Username:</td>
<td><input name="username" type="text" size=30></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" size=30></td>
</tr>
<td></td>
<td align="left"><input type=submit value="Sign In"></td>
</tr>
<tr>
<td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <font size=-1 color="#0000EE">Sign UP Now !</font></td>
</tr>
</table>
This is located at http://www.example.com/index.php
I have tried this code, but not works. This I got from someone who has answered at another question.
<?php
$username="username";
$password="password";
$url="http://www.example.com/index.php";
$postdata = "username=".$username."&password=".$password;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, 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");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
header('Location: track.html');
//echo $result;
curl_close($ch);
?>
Any help would be appreciated, Thanks in advance.
This is unsecure, but it's a way to do it
<?php
if (isset($_POST['username']))
{
file_get_contents("http://otherwebsite/page.php?login=".$_POST['username']."&password=".$_POST['password'])
}
?>

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

PHP cURL with header not working

I am trying to send data to a remote page using curl
Here is the soruce of the form section :
<form action="" method="POST" enctype="multipart/form-data">
<table align="center" cellspacing="0" cellpadding="5">
<tr><td>Type: </td><td width=100%><select name="service">
<option value="3">blah blah</option>
<option value="4">blah blah </option>
<option value="10"blll</option>
<option value="11">bbbb</option>
</select></td>
<tr><td>Link: </td><td><textarea name="url" cols="120" rows="10"></textarea></td>
<tr><td>Quantity: </td><td><input type="text" name="count" placeholder=""></td>
<tr><td>Initial Count (not required): </td><td><input type="text" name="incount" placeholder="" value="-1"></td>
<tr><td colspan=2><input type="submit" name="submit" value="Submit"></td>
</table>
</form>
I am using this curL CODE :
$header = array("Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryg5cfCMAC4o4JEbaz");
$postfields = array();
$postfields[] = array("service", "10");
$postfields[] = array("url", "something");
$postfields[] = array("count", "1000");
$postfields[] = array("incount", "-1");
$postfields[] = array("submit", "Submit");
$proxy = '155.241.126.244:60099';
$proxyauth = '123:123';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://xxxx/xx/news.php");
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, "http://xxxx/xx/news.php");
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_exec ($ch);
curl_close($ch);
This doesn't seem to work ( NO ERROR ON THIS SIDE , DATA IS NOT RECEIVING ON THE OTHER END ) , What is it i am doing wrong here ? Is it the headers ? I think the enctype="multipart/form-data" is my enemy ..
Add the following option:
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if you don't care about certificate checking and want to disable is.
Note that the following options MUST being used together:
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

How do I log in to an https that are using javacookies with Curl?

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.

PHP Form - Fetch file and download using CURL

Now Delicious is closing down, I tried to make a PHP form for a few friends to use to download there bookmarks:
Vising this url: https://api.del.icio.us/v1/posts/all
You get prompted for a username and password then presented with XML, I want to automate the download of the XML returned.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$username = $_POST['username'];
$password = $_POST['password'];
$url = "https://api.del.icio.us/v1/posts/all"
?>
<form ACTION="<?php echo $PHP_SELF;?>" name="bookmarkform" METHOD="POST" align="center">
<table>
<tr>
<td>
<label>Username</label>
</td>
<td>
<input NAME="username" tabindex="1">
</td>
</tr>
<tr>
<td>
<label>Password</label>
</td>
<td>
<input NAME="password" tabindex="2">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input TYPE="submit" tabindex="3" value="Submit!">
</td>
</tr>
</table>
</form>
Im missing something here but cant see what? Any help appreciated : )
Well, I'm not familiar with Delicious API, but my first suggestions is not to use undefined variables:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$url = "https://api.del.icio.us/v1/posts/all"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>

Categories