file_get_contents

Ames and I had a great move from Gainesville to Columbia! Everything between packing and closing when smooth, and although we’ve been working really hard on fixing the place up, we’re really happy with our first home. In fact, I wanted to spend my free time before work this morning finishing up my do-it-yourself post on removing popcorn ceilings, but I when I checked my gmail, I had over 100 comment spams to delete from mister aaa@aaa.com. If you have a Movable Type blog, you probably know him well…all he ever says is “Interesting!”, “WOW Nice Site!” I’ve had problems from him since before I moved to Dreamhost, but since then I haven’t been able to get MTBlacklist working to block him. Well, after deleting all those comments, I was pretty set on getting that fixed. Just as I figured, it was a permissions issue. After chmodding some mt files back to 755, I was up and running again with my spam filters, and just for good measure, I installed the latest version of Blacklist as well.

Since I was already in troubleshooting mode, I decided to tackle my Smart 404/Search problems. I kept getting “URL file-access is disabled in the server configuration” error whenever I tried to search or go to a non-existing url. I knew it all worked before, so I started snooping through my code and eventually figured out that Dreamhost has disabled the PHP option allow_url_fopen…which in turn kills file_get_contents. Argh! Fortunately, they’ve setup a workaround using curl.

I know Mike Davidson must have fixed this issue on his site because he’s a dreamhost user too, but I didn’t find anything on the related post or comments, so if you’ve followed his method too, here’s a fix:

In your 404.php page, change:

$full_page = file_get_contents($full_search_url);

To:

$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $full_search_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$full_page = curl_exec($ch);
curl_close($ch);

…and in your search.php page, change:

$search_results = implode('', file($link));

To:

$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$search_results = implode('', array($file_contents));

How much fun is THAT!?!? I don’t think I know anyone who this applies to, but I thought I’d write it up anyway in case I ever need it again. Hopefully I’ll get that popcorn removal post up sometime next week, cause I know you’re ALL dying to get rid of the popcorn ceilings in your houses.

7 comments on “file_get_contents

Justin P. says:

So this is a replacement for one line in Mike’s solution? Hmm, too bad I’m not running MT. Sounds cool.

re: Popcorn ceiling. You know that stuff has asbestos in it right? I know that’s probably why you had masks on in those photos, but dang, it gets everywhere (eyes, ears, etc..). Nasty.

Your new house looks great, the new work environment looks comfy 🙂

Yea, I can’t really take credit for any of the above code. 🙂 The solution was from Mike D’s website, and the fix was from the Dreamhost page (both linked above)…I just put 2 and 2 together.

Asbestos-containing popcorn was banned in 1978, and our house was built around that time, so there’s a possibility that it contained asbestos. We decided to chance it though and remove it ourselves. We were sure to cover the air ducts and wear masks during the process. The EPA Info on Asbestos is pretty scary, until you read that “People who get asbestosis have usually been exposed to high levels of asbestos for a long time.” and that there are no studies on short term exposure. I think it’s a little overkill.

Dustin says:

Glad your move went well.
It’s time for me to move now.

Btw, WOW Nice Site!

j/k. Don’t blacklist me. I’m coo.

Interesting!

the fact that dreamhost turned off allow_url_fopen has been a pain in my side since they did it about 3 months ago. For my senior portfolio one of my websites was based off the allow_url_fopen function set. The day before the presentation is when dreamhost turned it off (and the default is not to receive those messages). To bad nobody every told me not to use allow_url_fopen instead of cURL.

OUCH! Sorry to hear about that. I knew I switched over to Dreamhost before they started that, but I didn’t know it was only 3 months ago. I never knew (still don’t know) that it isn’t kosher to use allow_url_fopen. I can understand how a hacker that is able to get to your php source code could do some damage with it…but if a malicious person has access to my php source code, I might as well kiss the entire site goodbye anyway.

Jay says:

Here we are two years later and your post saved me quite a bit of time today. A friend on a Dreamhost account had a plugin that used file_get_contents and I replaced the call with your script.

Thanks for putting it up.

Leave a Reply to Justin P. Cancel reply

Your email address will not be published. Required fields are marked *

Back to the top!