0

Let's say one website has a catalog made with Servlets. How would one, theoretically, embed that catalog application inside his own website using PHP? Is that possible?

user1701467
  • 285
  • 2
  • 7
  • 20

1 Answers1

1

Easiest way would be using HTML <iframe>.

<iframe src="http://other.com/catalog"></iframe>

This way the webbrowser will handle it all transparently.

If you really need to inline the HTML output of the other catalog webapp in your own HTML output, then you'd need to use curl to obtain it, parse the HTML, extract the body elements (you can't nest <html>, inside <html>) and manipulate all relative links in HTML <a>, <link>, <script>, <img>, etc elements so that they point to your domain instead (otherwise CSS/JS/images/links cease to work) and finally just echo it to the response. This all is however not exactly trivial. You're then basically acting as a proxy for the other webapp. Note that you'd possibly also need to proxy all requests from <form> submits originating from the HTML of the other webapp, if any.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • So, with iframe I wouldn't be able to really hide some things? It would just be like a page within another page? – user1701467 Oct 19 '12 at 17:10
  • 1
    If you need to manipulate the output, then there's really no other way than to proxy everything. It'd probably be much easier to ask the owner of the other webapp if there isn't some public SOAP or REST webservice API available for the catalog and then use it instead, in combination with your own HTML presentation layer. – BalusC Oct 19 '12 at 17:12