Jump to content

Grabbing Data From Website After Login Via Curl.


hockey97

Recommended Posts

Hi, I am doing business with a supplier. However, the supplier has an api that I can use but it's only to process orders. I buy the products at a wholesale price. They have 2 methods. one where I can have them charge my clients and then I get comission off the sale and they ship directly to my clients. Or I can buy them and it be shipped to me. I have to prepay for them. I have to have money in a virtual wallet. I can only refill the wallet with a minimum of $40.

 

So, here is the issue. The issue is that the supplier doesn't have the api to refill the wallet. I have to manually login and refill the wallet. I want to automate this process.

 

So, the website is using https and apache mod_rewrite. So, currently I setup the ssl part correctly with the certificate etc and verifying and all goes good.

 

The problem is that I cannot login. I get no error at all. When I ECHO out the curl execution I get the page displayed with the login form. It's showing that it cannot get past the login page.

 

I would like to know how I can access my account because I need to grab my wallet total to determine if I need to refill and if so I will refil $40 at minimum. So anything I am buying to resell is less then $40 in total. I will have to refill at $40. If the total is higher then $40 then I will refill the amount that my order is totalled too. So if I am buying $50 dollars worth of stuff. I would refill $50 for my wallet.

 

So, I need to login and access my account and then grab wallet total and get total of the order to process. I then will figure out if I need to refill my wallet and then verify if it's refilled. Then once all is good then process the order to the company.

 

I used live headers to see the headers when I login. I then use that url as the url for the curl target.

 

it's something like https://domain.com/login

 

I need someone to show me either a tutorial or explain the whole concept. You don't need to provide me with the code. I pretty much can write the code. Just need to know what functions I need to use or what Curl opts I need to use to successfully log into a https website. I am currently echoing out the curl execution to visually see that it gets logged in. I am looking for that page that shows my account being accessed.

Link to comment
Share on other sites

Show us your code, and we should be able to help you. Without it we're simply guessing, and it tends to be just a waste of time. So, code is good. ;)

 

Here is the code:

 

function curl_with_cookies($url, $postdata = false, $cookies = false, $ssl = false, $url_encode = false , $post_encode = false, $unserialize = false )
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_USERAGENT, "spider");
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
if($ssl)
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSLVERSION,3);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, getcwd() . "/domain_x.pem");
}
if($cookies)
{
if($postdata)
{
$make_file = fopen('cookies.txt', 'w+');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookies.txt');
}
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
}
if($postdata)
{
if($post_encode){$postdata = http_build_query($postdata);}
if($url_encode){$postdata = urlencode($static_post);}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
}
$ret = curl_exec($curl);
if ($ret === FALSE) {
$ret = curl_error($curl);
}
if($unserialize){
$ret = unserialize($ret);}
curl_close($curl);
return $ret;
}

 

I made that function and here is how it's used:

 

$data = "?username=user&password=pass";

 

curl_with_cookies('https://user.supplier.com/login',$data, true, true);

Edited by hockey97
Link to comment
Share on other sites

If I recall correctly, the question mark shouldn't be a part of the POST data. So try without it.

Should that prove fruitless, try doing a var_dump ($_POST); on the receiving script, to see what you get.

 

I don't get what you mean? I am sending a post login data to my suppliers website. It's not mine. They have an api but that api doesn't allow me to login to my account to check my virtual wallet. I need to log into my account to check my virtual wallet to see the balance and then determine if I need to refill it and if so then by how much? the minimum I can refill it is by $40. I cannot refill by less.

Link to comment
Share on other sites

I echo out what is curl executed. I get a login html page back. Yet, I am supposed to get the page after you login. However, I don't get that page.

 

Since I am trying to login to my suppliers webpage. so I can check my wallet balance and figure out if I have to refill my wallet to process orders via their api.

 

I can process orders via their api but I cannot refill my wallet and they gave me permission to use Curl to automate the process where I log into my account and then check the wallet balance and figure out how much refilling I need if any.

 

They only allow a minimum of $40 bucks to refill at each refill. So I can't refill my wallet by $39 or less.

Link to comment
Share on other sites

If I recall correctly, the question mark shouldn't be a part of the POST data. So try without it.

Should that prove fruitless, try doing a var_dump ($_POST); on the receiving script, to see what you get.

 

Ya, it's supposed to be there. I even tried not using it. It won't show me any webpage at all. It returns nothing back.

 

I am pretty sure you need to include that question mark. It's urlencoded or supposed to be urlencoded.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.