tags:

views:

57

answers:

4

Hi! I'm not very good at explaining in english but i'll give it a go. Hope you understand.

In php i have this script that fetches an URL and displays the content. So far so good. The content is shown like this:

eg. site.php?url=http://google.com

But WHEN i click on something in the page, eg. google.com, then my site disappears and the user is browsed to google.com

How do i do that when they click on a link, they should stay in my site and only the URL parameter should change.

Thanks!

I hope u understood me, i don't write english very well...

A: 
<?php
 $url = 'http://www.google.com';
 echo '<a href="?' . urlencode ($url) . 'url=">Google</a>';
?>
dutch
hum dutch, if i am using a input were users input the URL and then pass on the url to the script, how do i do then?
+2  A: 

You need to go through all of the links on the page, replacing them with links to your site, so that

<a href="http://www.something.com"&gt;Some Link</a>

...is turned into:

<a href="http://www.yoursite.com/site.php?url=http://www.something.com"&gt;Some Link</a>

Note that you'll have to all kinds of fancy URL encoding and escaping to make it work correctly. Have fun!

Aric TenEyck
Yup i will do that with regex! Thank u for the idea.
A: 

Basically, what you are trying to do is create a proxy, in PHP ?

Well, that will not be such an easy tak, I'm afraid : you will have to find every links in the HTML content, and rewrite them one by one... And that for those which you want rewritten (probably not all, so)

A few ideas :

  • You could try doing this with a couple regex... That'll end up quite messy...
  • Same with str_replace and the like...
  • Maybe with DOMDocument::loadHTML, some DOM and XPath manipulations... But that's probably be hell on earth too...

So, no miracle idea in PHP, I'm afraid :-(


I have not tried it myself, but if you are working with Apache and you are admin of your server, maybe Apache's mod_proxy_http and mod_proxy could help you (not sure, though)


Speaking about a PHP Proxy, maybe you could take a look at some existing software that seem to already do the kind of stuff you want.

For instance :

There might others, btw...

Quoting the page of Glype :

Glype proxy script is a free-to-use, web-based proxy script written in PHP. Similar to a typical proxy server, a web-proxy script downloads requested web pages and files and forwards them back to the user. The service is provided by a web page itself, which allows instant access to the proxy without editing your browser connection settings.

Unfortunatly, the demo page doesn't seem to be working right now :-(

I have not looked into what those can do... But maybe they might help you ;-)
ie, there might be some ideas in their code-source that you could base your script upon ?

Pascal MARTIN
+1  A: 

I hope this is relevant: Another technique would be to open the related site in, [gasp], an iframe. That way any links clicked in the iframe would stay in its own frame, much like how the digg bar or facebook outbound links work, but you could still maintain control of the surrounding content.

stereointeractive.com