cURL 100% look identical to my request using regular browser

2

I need to do some standard functions that I always do manually, and I would like to automate this. I tested it with iframe , but without success, it does not read the document nodes.

I thought of using the cURL library, so I get the contents of the page (could be file_get_contents () ), the options return to the login page (including logged in, asking only to proceed) , but if I access the same page in my browser, it is not redirected to the login screen.

So the question, what to do to make the cURL request 100% identical to what I do in my regular browser, that is, if I did, I would go to the page I pointed, instead of logging back in.

Note: In cURL I have set CURLOPT_COOKIEFILE to a .txt file where you have cookies (which I make sure I am logged in) cURL back to login page (already logged in, just asking permission to continue)

I believe that the site somehow detects this, would it be some constant that I stopped defining in cURL ?

Here's how I set up cURL today:

$url = "http://trade.aliexpress.com/order_detail.htm?orderId=71064520859834";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);

curl_exec($ch);
    
asked by anonymous 20.11.2015 / 15:33

1 answer

1

You are always being redirected to the login screen because you are creating a jar cookie but it is empty. You need popular curl cookies with your current cookies.

curl_setopt($ch, CURLOPT_COOKIE, $_SERVER["HTTP_COOKIE"]);

However, please note that you may still be redirected to the login page because other authentication mechanisms may exist on the site.

    
20.11.2015 / 18:27