0

there.

I want to get HTML response of my magento shop page.

So I coded a small PHP program for this with using CURL library(and I tried also with file_get_contents());

$crl = curl_init();
$timeout = 10;
curl_setopt($crl, CURLPT_URL, $url);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$response = curl_exec($crl);
curl_close($crl);

At first glance, it works well. But I found one problem.

My shop has 2 multilingual store. So I tried 2 urls. "http://MYSHOP.COM/TARGET_PAGE/?___store=default&___from_store=french" and "http://MYSHOP.COM/TARGET_PAGE/?___store=french&___from_store=default"

However the both returns are same. they return always 'default' store result. When I open these urls on my browser, they shows right result with each language. Why is it caused?

I guess it might be related with some cookie issue. how can I get the right result?

PS. I searched browser cookies with developer tools of Chrome, but I could not find any suspicious cookies which might be related with language info.

3
  • Have you tried to add session support for curl request?
    – Amasty
    Aug 13, 2014 at 8:29
  • I need more information about that. What kind of session support??
    – Sean
    Aug 13, 2014 at 8:31
  • Have added the answer
    – Amasty
    Aug 13, 2014 at 8:53

1 Answer 1

0

Try to add

`curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"); 
$cookie_file = "cookie1.txt";
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);`

Also, try to you add URL params using separate curl function, not just as a part of the link

4
  • Also, what is about just file_get_contents?
    – Amasty
    Aug 13, 2014 at 8:52
  • thanks for your reply. I tried file_get_contents function instead of curl. :D
    – Sean
    Aug 13, 2014 at 9:04
  • I'll try some hours later (sorry, I must finish other works before this), and I'll report the result. and I will accept wheter it works or not. :) Thanks again.
    – Sean
    Aug 13, 2014 at 9:58
  • Hi, At first, I failed with your code. Frankly said, I cannot understand How it works. But I got a hint from your codes. I tried additional code. That is ridiculous simple. curl_setopt($crl, CURLOPT_COOKIE, $cookie); It works fine. Thanks your help.
    – Sean
    Aug 13, 2014 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.