Power of file_get_contents() PHP function
Posted at 5:11 am on January 3rd, 2008 in Tips & Tricks Hits: 3,483

Ever since the introduction of PHP5, we have been getting a lot of complaints that most webhostings are actually restricting the include() feature of remote files/links. This is actually a default settings in PHP5 to avoid hacks and DDos attacks. This simply means only local files can be included in any PHP applications. First workaround that anyone can think about is to ask our webhosting to enable back this feature, but i am not sure how well this would work!

To burn my time i just wanted to create a PHP application which would simply access pages behind any firewall or proxies. Well trust me this is not any proxy script you might be thinking about or even would want to have. It will just peek the contents of the page if it is blocked by using the include() feature. But as i was coding this simply and messy script i noticed that my host has disabled include() function for remote files.

After digging here and there and also using my basic knowledge of PHP, i came upon the function file_get_contents() which does exactly what i wanted for my script. It works almost the same as an include function but more towards displaying the page contents.

By using this function i managed to complete my simply script called “Peek-Into”. Here is the code i used in my script which simply bypasses the usage of included():

<?php
// code to include a file without using include
$_url = $_POST['url'];
if ( $_url != "" ) {
 $url = file_get_contents("$_url");
 echo $url;
}
?>

Some might be wondering what is the purpose of this code? Well it is just a part of my code for the script “Peek-Into” which allows you to peek and have a glance of any pages even those blocked behind firewalls. You can check out the demo of my script HERE.


|

  • http://ramesh.ws ramesh

    Please take note the PHP script is just peeking file and not a full proxy script. I might work on making it one soon, but for now it is just a simple code to show the power of the PHP function. So stop bitching that the script doesn’t work. Thanks :)

 
About Me

I'm ramesh from Perak, Malaysia. Blogging is my hobby hence this blog is my second home to share my life, interests and etc. One can always interact with me by using the mediums below.



Blog Menu

» Main Page
» Blogging ( 137 | rss )
» Info Tech ( 43 | rss )
» Mesh Views ( 3 | rss )
» My Mesh ( 17 | rss )
» My Poems ( 6 | rss )
» My Workshop ( 16 | rss )
» myIndians-World ( 45 | rss )
» Places & Events ( 62 | rss )
» Shoot Me ( 17 | rss )
» Tips & Tricks ( 21 | rss )
» Contact Me


Micro Mesh



Get Updates



 

page made and maintained by mesh