At school, there are blocks on sites. I intend to undo that. Even if I don’t, I like this idea. So: I have a php page (source.php) to get source code of any site (no cross site ajax).
<?php
echo file_get_contents(urldecode($_GET["url"]));
?>
<script>
if(document.getElementsByTagName("base")[0])
document.getElementsByTagName("base")[0].href="<?php echo $_GET["url"] ?>";
else
document.head.appendChild(document.createElement("base").href="<?php
echo $_GET["url"] ?>");
</script>
Simple. Here is the index.html
<html><head><title>Unblocker</title></head><body>
<div width="100%" height="10%">
<form onsubmit="return go()">
<input id="url" value="http://www.google.com/">
<input type="submit" value="Go">
</form>
</div>
<div width="100%" height="90%">
<iframe src="http://www.google.com/" width="100%" height="100%" id="frame">
</iframe>
</div></body></html>
And now the javascript (to be inserted into the head tag)
function go(){
url=document.getElementById("url").value;
frame=document.getElementById("frame");
//do some url validations, not posting cause doesn't matter
if(url.isValid)//example
frame.contentWindow.location=location.protocol+"//"+location.hostname+"/
source.php?url="+url;
return false;//to prevent page reload
}
A couple of things: First, is this legal, taking whole source codes and displaying them despite my good intent? Also, will it work, or is there anything obvious that can make it better? I know that the server side can’t be filtered (assuming that this site is not blocked!). I know that it is very limited, but I might be able to expand it to allow clicking links and all.
You intend to write a proxy. I think you should simply use http://www.phpproxy.net or look for a proxy software and install it on your server.
OR you could go on and do it. You could end up with a product and you will have learned a lot about the HTTP protocol and creating a proxy. Surely more than you can learn at school.
Proxies are not illegal, but it’s probably against your school rules, assuming they have those rules written down somewhere and they didn’t forget about the proxy thing. 🙂