php - Getting html data from another website and caching + is it possible as end user? -


I have the following code in WordPress, which takes the HTML code for the menu at a shop so that the blog and the shop A completely different system) is the same dynamic menu, though it takes some time to load, code is disabled or I need to go down the caching route?

  & lt ;? Php $ url = 'http: // localhost: 8080 / mystore /'; $ Content = file_get_contents ($ url); $ First_step = Explosion ('& lt; nav class = "top">, $ content); $ Sec_stop = explosion ("& lt; / nav & gt;", $ first_step [1]); Echo $ sec_step [0]; ? & Gt;  

My second question is that ideally I would like to include the login / my account link from the shop on the blog, although this session is based on the shop, there is no such code above which Does the end user move the session to the account? To get content, like loading the external link on behalf of the end user (as the user session will be active on the shop)

I answer your first question, it depends on how often the menu changes, you can consider caching using HTML. Your example looks like this:

  & lt ;? Php if (false === ($ content = get_transient ('shop_menu_html'))) // // transient is not present or expired, so set it $ url = 'www.externalurl.com'; $ Content = file_get_contents ($ url); Set_transient ('shop_menu_html', $ content, 12 * HOUR_IN_SECONDS); } $ First_step = Explosion ('& lt; neo class = "top" & gt;' $ $ content); $ Sec_stop = explosion ("& lt; / nav & gt;", $ first_step [1]); Echo $ sec_step [0]; ? & Gt;  

Comments