iframe / file_get_contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cucumberdude
Forum Newbie
Posts: 14
Joined: Sun Dec 12, 2010 11:53 pm

iframe / file_get_contents

Post by Cucumberdude »

I'm trying to configure a system like so:
client requests external page from my site -> my site requests page from the site ->returns the external page to the user

I'm using file_get_contents to do this.
The only problem is, if they click a link, it brings them to the page relative to MY site, not the requested site. IE, if they click a link to a youtube vid which usually reads 'youtube.com/12412412' it brings them to 'mywebsite.com/youtube.com/1214141'.

I thought that perhaps using an Iframe was the way to go, but do Iframes work through the server or just request the page from the client side?

Either way, I'd like a way to at least make pages' links work.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: iframe / file_get_contents

Post by danwguy »

an iFrame will work just fine, you can click on any link in an iFrame and it will be on that website not yours.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: iframe / file_get_contents

Post by John Cartwright »

iframes are nothing more than a new window embedded in your active window. It is entirely client side and will never touch your server side.

If you want to simulate the same behavior with file_get_contents(), you need to rewrite your url's in the header to point to your domain, and have your application handle the new links appropriately. I.e.,

http://google.com

Would become http://yourdomain.com/your_script.php?p ... google.com (or something down this line).

From there, you need to check whether $_GET['page'] is an absolute url, or a relative url (and if so, prepend the hostname information).
Post Reply