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


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.





Related Posts

SimplePie and mySQL Special Character Issue - Posted @ 2:25 pm on July 4th, 2008
Automatically Add Scrollbar To Overflowing Images - Posted @ 8:06 pm on October 27th, 2008
Display Simplepie RSS Feed In Reverse Order - Posted @ 11:45 pm on February 28th, 2010


Recommended



Comments

1. ramesh @ 05:11 am on January 3rd, 2008

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 :)


Leave a comment:

Your comment :

 
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.



Blog Menu



Recent Friends



 

page made and maintained by mesh