1

I got a URL from a ecommerce website and when i access it i get all the last 5 products that i've visited in their site. I don't know how it works, i guess it's because of the cookie that this ecommerce website have left in my browser.

I would like to use this URL to show in my website something like this: "The Last 5 Products You Have Seen at X Ecommerce Website".

But to do that this URL must be executed in somehow in the client side and i will still need to get the JSON content returned by this URL.

Is there exist anyway to do that by using PHP or any other web technology?

Thank you!

Andre
  • 431
  • 7
  • 23
  • First you need to know exactly how they do it... And only after that you can try to reproduce it – E_p May 16 '17 at 20:51
  • You could use JavaScript AJAX to call the API if Cross-Origin is allowed to where your URL can call upon another external URL to get the JSON response. If that isn't possible, I would suggest using PHP CURL on the server side to get the JSON payload, then return that payload to your client from your server. See something like this: http://stackoverflow.com/questions/16700960/how-to-use-curl-to-get-json-data-and-decode-the-data – Woodrow May 16 '17 at 20:52

2 Answers2

1

It might be cookies, localStorage (there are other APIs to save data on local computer, imo they are unused or deprecated e.g. openDatabase) or last views could be connected with account and saved on internal database.

You should use AJAX, but by default in browser mechanism called CORS blocks all requests coming from other domain than resource.

In PHP you can download external page using file_get_contents function or cURL library, but without localStorage/cookies (which can be accessed from JS executed on domain, where that cookies are saved).

Reski
  • 169
  • 7
0

AJAX is your option for client side requests. Here's the jQuery guide for it.

https://api.jquery.com/jquery.ajax/

Here's a quick example:

$.ajax({
       url: "http://ecommerce.com/your/url/here",
       method: 'get', 
       dataType: 'json', //if you're sure its returning json you can set this
       success: function(data) {
           //handle success json here
           //be sure that you're going to receive json though, possibly could receive some other data type and you should handle appropriately
       },
       error: function(error) {
           //handle error json here
       }
});
JacobW
  • 826
  • 5
  • 15