Logging Into AliBaba.com programmatically - php

I am trying to figure out how to login to the website https://login.alibaba.com using PHP and CURL. I am using the code below but it does not seem to be working. How would you recommend I login to this site automatically?
My current code:
<?
$cookie = "cookie.txt";
// set global curl options
$curloptions = array(
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',
CURLOPT_TIMEOUT => 60,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_REFERER => 'http://www.alibaba.com'
);
// set userinfo
$username = 'xxxxxxxxxxx';
$password = 'xxxxxxxxxxx';
// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);
// make a dummy request to generate a session
curl_http_request('https://login.alibaba.com', $curloptions);
// login
curl_http_request('https://login.alibaba.com',
array(
CURLOPT_POSTFIELDS => 'xloginPassport=' . $username . '&xloginPassword=' . $password . '&noCsrfToken=&xloginCheckToken=&rememberme=&runatm=',
CURLOPT_POST => TRUE
), $curloptions
);
//example request
echo curl_http_request('https://login.alibaba.com',
array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE
), $curloptions
);
function curl_http_request ($url, $moreoptions = array(), $options = array())
{
foreach ($moreoptions as $k => $v) $options[$k] = $v;
$handle = curl_init($url);
curl_setopt_array($handle, $options);
ob_start();
$buffer = curl_exec($handle);
ob_end_clean();
curl_close($handle);
return $buffer;
}
?>

They are using some token generation method on login, so unless you know how to generate the same, just use their web login.
Here's a typical login request looks like:
https://login.alibaba.com/xman/xlogin.js?pd=alibaba&pageFrom=standardlogin&u_token=Bf0323500b707423d50c96aae931e204b&xloginPassport=andreaswongg70&xloginPassword=10fd852ff6603865cf632b59d935e56b&dmtrack_pageid=ca1b1fe2cdcc700d4f66917813628a849a71fcca49

Related

PHP Curl Response

I am currently working with an API for a little project of mine that will only accept POST requests, however no matter what I seem to do I cannot get a response out of it, I have tried echoing the response, I have tried returning it, I have tried using print_r and nothing works. Can someone tell me what I am doing wrong?
<?php
$applicationPass = $_GET['appPass'];
$email = $_GET['email'];
$password = $_GET['password'];
if ($applicationPass == "abc123"){
//
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_URL => 'http://api.minergate.com/1.0/auth/login/',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'email' => urlencode($_GET['email']),
'password' => urlencode($_GET['password'])
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo $resp;
//
}else{
die();
}
?>
Here is my updated code, I get a little bit of a different response with their new API that took forever to find.
<?php
$applicationPass = $_GET['appPass'];
$email = $_GET['email'];
$password = $_GET['password'];
if ($applicationPass == "abc123"){
//
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_URL => 'https://minergate.com/api/2.2/auth/login',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0',
CURLOPT_CUSTOMREQUEST => 'POST',
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'email: ' . $email,
'password: ' . $password
)),
CURLOPT_POSTFIELDS => array(
'email' => urlencode($email),
'password' => urlencode($password)
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo $resp;
//
}else{
die();
}
?>

wordpress 4.5 automatic Login with PHP CURL

I'm using php curl for automatic login into wordpress panel but code does n't work
<?php
$ch = curl_init();
$postData = array('log'=> 'admin',
'pwd' => '123',
'wp-submit' => '%D9%88%D8%B1%D9%88%D8%AF',
'redirect_to' => 'http://localhost/wp/wp-admin/',
'testcookie' => '1'
);
$cookie = basename('cookie.txt');
$opt = array(
CURLOPT_URL => 'http://localhost/wp/wp-login.php',
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0',
CURLOPT_COOKIEFILE => $cookie
);
curl_setopt_array($ch,$opt);
$out = curl_exec($ch);
echo $out;
?>
wordpress login panel return :
ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.
How do fix error
Your Login function :
function Login($data){
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-config.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-includes/wp-db.php');
global $db;
global $json;
$credentials = array();
$secure_cookie='';
$username=$_POST['user_login'];
$password=$_POST['user_pass'];
if ( !empty($_POST['remember']) )
$credentials['remember'] = true;
else
$credentials['remember'] = false;
$secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);
$user = wp_authenticate($username, $password);
if ( ! is_wp_error($user) )
{
$json['success'] = true;
$json['data'] = $user;
} else {
$json['success'] = false;
$json['data'] = "Please Wrong Username And Password.";
}
Your Curl format:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"your_url");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "user_login=dcm&user_pass=123456&api=Login");
curl_exec ($curl);
curl_close ($curl);

Magento login curl

i'm trying to make a magento login with curl, what I need can be on the same server as magento
There is my code, currently not working:
$data = array(login[username]"=>"email", "login[password]"=>"password");
$url="https://example.com/customer/account/loginPost/";
$options=array();
$ch = curl_init();
$params = http_build_query($params);
$def_options = array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_FOLLOWLOCATION =>1,
CURLOPT_HEADER=>0,
CURLOPT_RETURNTRANSFER =>1,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR=> '/tmp/cookies.txt',
CURLOPT_COOKIEFILE=>'/tmp/cookies.txt',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST=> true,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_TIMEOUT => 100,
CURLOPT_VERBOSE=>TRUE,
CURLOPT_STDERR=>$verbose
);
$def_options += $options;
curl_setopt_array($ch,$def_options);
$response = trim(curl_exec($ch));
$info = curl_getinfo($ch);
curl_close($ch);
echo $response;
This simply redirects me on the login page without any error or successful login, it seems to do not send any POST data.
Any advice?
first. You've missed a quote sign at first line:
$data = array("login[username]"=>"email", "login[password]"=>"password");
^
second. change $params = http_build_query($params); to $data = http_build_query($data);
and you are ready to go.

Creating cURL With Different POST DATA

I created a code algorithm that creates 10 different numbers. By using the PHP cURL I want to send POST requests to a website with those different 10 numbers, and then get the response bodies for them. Here is my example code for generating 10 different numbers:
function solver($aaa,$bbb,$number) {
$solo = substr($aaa,0,9);
$x=substr($solo,0,5);
$y=substr($solo,5,4);
if ($bbb == 0) {
for ($i = 1; $i <= $number ; $i++ ) {
$xx=$x+8*$i;
$dokuz=$xx.$y-1*$i;
$yeni=$dokuz;
echo $yeni."<br>";
}
}
}
solver("12345678912",0,10);
Here is the cURL:
<?
$url = "http:/example.com/solver.aspx";
$postdata = 'number'.'='.$yeni;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
preg_match_all("/id=\"__VIEWSTATE\" value=\"(.*?)\"/", $result, $arr_viewstate);
$viewstate = urlencode($arr_viewstate[1][0]);
preg_match_all("/id=\"__EVENTVALIDATION\" value=\"(.*?)\"/", $result, $arr_validation);
$eventvalidation = urlencode($arr_validation[1][0]);
preg_match_all("/id=\"__LASTFOCUS\" value=\"(.*?)\"/", $result, $arr_lastfocus);
$lastfocus = urlencode($arr_lastfocus[1][0]);
preg_match_all("/id=\"__EVENTTARGET\" value=\"(.*?)\"/", $result, $arr_eventtarget);
$eventtarget = urlencode($arr_eventtarget[1][0]);
preg_match_all("/id=\"__EVENTARGUMENT\" value=\"(.*?)\"/", $result, $arr_eventargument);
$eventargument = urlencode($arr_eventargument[1][0]);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => '__EVENTTARGET='.$eventtarget.'&__EVENTARGUMENT='.$eventargument.'&__VIEWSTATE='.$viewstate.'&__EVENTVALIDATION='.$eventvalidation.'&__LASTFOCUS='.$lastfocus.'&'.$postdata.'&Submit=submit');
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$result = curl_exec ($ch);
preg_match("/<input name=\"Adi\" type=\"text\" value=\"(.*?)\" maxlength=\"25\" id=\"txtAdi\" disabled=\"disabled\" class=\"aspNetDisabled\" \/>/", $result, $adi);
$cikan = "<b>".$yeni."</b>"." "." ".$adi[1]." ";
print($cikan);
curl_close ($ch);
So, I am trying to make the cURL reply 10 times with those 10 different numbers. Can anyone help me about this issue?
Thank you,

Server not responding using Curl POST Request

I am using this code to get the contents of a post request url using php curl
Code looks as below:
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'barcode' => 'CP021325078TR',
'security_code' => $capcha2
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo "<pre>";
var_dump($resp);
echo "</pre>";
The result doesn’t seem to return anything at all.
What is wrong with this code?
Try this:
$url = 'http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php';
$postvals = array(
'barcode' => 'CP021325078TR',
'security_code' => $capcha2
);
$resp = Request($url,$postvals);
echo "<pre>"; var_dump($resp); exit;
...
function Request($url,$params=array()){
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true
);
if(!empty($params)){
$curlOpts[CURLOPT_POST] = true;
$curlOpts[CURLOPT_POSTFIELDS] = $params;
}
curl_setopt_array($ch,$curlOpts);
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch); exit;
}
curl_close($ch);
return $answer;
}
EDIT:
I tested this and got:
Could not resolve host: www1.ptt.gov.tr
So make sure you're calling the right endpoint.
Actually you need to set this variable
$captcha2
To use it here -
'security_code' => $capcha2

Categories