views:

65

answers:

1

Would it be possible if a user clicked on a link inside an iframe showing an outside site to have the webpage request be routed through the server that the iframe is hosted on?

Example: Iframe on somesite.com showing google.com User clicks a result link to someothersite.com The request is sent through somesite.com's server and is logged so that they now have a record of what link they clicked on.

Possible? Not?

Thanks.

+1  A: 

No, the browser's security model should prevent you from tampering with a website on a different domain (which you would have to do to intercept the clicks).

You could proxy the iframe through your own server and re-write it...

<ifram src="proxy.php?src=www.google.com"></iframe>

The basic idea of proxy.php would look something like (this is not supposed to be finished or even working - just to give you the idea of how it should work):

<?php

// Get the contents
$html = file_get_contents($_GET['src']);

// Rewrite the links
$html = preg_replace('/href=["\']?/i', 'href=clicky.php?src=', $html);

// Output the HTML
print($html);

?>
Greg
Ok. The so using a proxy would work. I'll try that.
GuyNoir
How would I go about doing this exactly? I've googled around a bit, but most of the results I get explain using an outside proxy, not your own server. Thanks.
GuyNoir