pewee2000 Posted August 27, 2009 Share Posted August 27, 2009 I am very new to php so please be kind. To put it simply: I have an external url eg. http://www.externalurl.com/index.php?token=61DKJH1B&source=WR What I want to be able to do is pull that page into my own url eg http://www.myurl.com/myphp.php?token=61DKJH1B&source=WR So basically I need to display the external page and still be able to change the variable in the url to feed to the external page. Essentially I just want to mask the original url but still feed it the token=61DKJH1B&source=WR. Any ideas would be much appreciated? Quote Link to comment https://forums.phpfreaks.com/topic/172092-loading-external-content/ Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 $contents = file_get_contents('http://www.externalurl.com/index.php?token=61DKJH1B&source=WR'); $contents = str_replace('http://www.externalurl.com/index.php', 'http://www.myurl.com/myphp.php?url=http://www.myurl.com/myphp.php', $contents); print $contents; Quote Link to comment https://forums.phpfreaks.com/topic/172092-loading-external-content/#findComment-907371 Share on other sites More sharing options...
pewee2000 Posted August 27, 2009 Author Share Posted August 27, 2009 Thanks so much for a quick and direct response. This works great, apart from the fact that some of the elements from the page are unformatted or missing. Im guessing this is because it is trying to run files local to my url folder that obviously exist on the other site. Is it possible to get the external content to run as if existing on its site? Don't know if this is possible, but hey worth an ask. Quote Link to comment https://forums.phpfreaks.com/topic/172092-loading-external-content/#findComment-907377 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 You'll need a preg_replace or something that modifies relative paths like: static/images/someimage.jpg to http://www.domain.com/static/images/someimage.jpg Quote Link to comment https://forums.phpfreaks.com/topic/172092-loading-external-content/#findComment-907379 Share on other sites More sharing options...
RichardRotterdam Posted August 27, 2009 Share Posted August 27, 2009 You can indeed use a regular expression to change the relative paths to absolute paths. You might also want to look at DOMdocument for fetching and modifying certain elements. Quote Link to comment https://forums.phpfreaks.com/topic/172092-loading-external-content/#findComment-907398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.