RE: Help - PHP Proxy 08-04-2013, 01:01 PM
#4
Well, this will hurt it if they show their entire url on the page, but a simple str_replace("http://www.blockedsite.com/", "http://localhost/?u=http:////www.blocksite.com/", $url); should work...
There are a few problems with this, it assumes every link starts with "http://www.", and as i said earlier, it will replace anything on the HTML shown...The solution to this would be running a RegEx or XML on it, looking for <a href="*"></a>, and replacing the contents...I'll make something with RegEx (Preg_Replace) in a few for ya...Won't be the best tho
Edit:
Here is a quick RegEx that i made, I really recommend improving on it, as it's still not fool proof (For example, if there is a class in the Anchor link, then it'll skip over it..., same with id etc etc), I'll make an another version, which uses a function instead of replacing expected stuff, still RegEx with the same problems again.... I highly recommend looking into a HTML/XML Parser to do what you want to do...
There are a few problems with this, it assumes every link starts with "http://www.", and as i said earlier, it will replace anything on the HTML shown...The solution to this would be running a RegEx or XML on it, looking for <a href="*"></a>, and replacing the contents...I'll make something with RegEx (Preg_Replace) in a few for ya...Won't be the best tho

Edit:
Here is a quick RegEx that i made, I really recommend improving on it, as it's still not fool proof (For example, if there is a class in the Anchor link, then it'll skip over it..., same with id etc etc), I'll make an another version, which uses a function instead of replacing expected stuff, still RegEx with the same problems again.... I highly recommend looking into a HTML/XML Parser to do what you want to do...
PHP Code:
<?php
$url = "http://google.com";
$page = file_get_contents($url);
$page = preg_replace("#\<a href=\"(.+)\">(.+)</a>#iUs", "<a href=\"http://localhost/?u=$1\">$2 - [Changed]</a>", $page);
echo $page;
?>
(This post was last modified: 08-04-2013, 01:12 PM by SLUAST.)


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)