PDA

View Full Version : Calling PHP function readfile() on own domain fails


kaptainkory
01-08-2007, 04:37 PM
The thing that is bugging me most is that this *used* to work (and a pretty important part of my site relies on it!), but has now started giving me a "Connection timed out" error when calling my own domain (or addon domain). Calling an outside domain works fine.

readfile("http://www.snakesofarkansas.com"); //Does not work - Primary Domain
readfile("http://www.fieldherpers.com"); //Does not work - Add-on Domain
readfile("http://www.google.com"); //Works - Outside Domain

I get the same results trying other methods to pass a file thru, such as file_get_contents(), fread(), fopen(), curl_ini(), etc. All of these also fail when calling my own domain, but work fine for an outside domain.

Any troubleshooting tips are appreciated. I seem to be locked out of calling my own domain using any of the PHP "pass thru" functions. Thanks.

areidmtm
01-08-2007, 04:40 PM
Have you tied using absolute URL? such as


<?php
readfile($_SERVER['root_document'] . '/folder/to/file.txt');
?>

kaptainkory
01-08-2007, 05:47 PM
I think you mean DOCUMENT_ROOT (not "root_document"), but yes this does work. However, this is of little benefit since I need the file to be PHP processed BEFORE displayed...the inclusion of a flat text file won't cut it. Really, the specific call I need to work is:


readfile("http://www.snakesofarkansas.com/galleries/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title");


Again, this *was* working...now, it isn't. Could someone else please confirm that they can successfully call the readfile() function on a URL of their OWN domain? (I might mention that my domain names are registered with GoDaddy, not Bluehost...if that matters?)

kaptainkory
01-08-2007, 05:48 PM
Also, I've checked that "allow_url_fopen" is enabled in php.ini. That isn't the problem. I've also temporarily deleted my .htaccess file, thinking that might be the problem...but got the same results. Just in case, here is my .htaccess:


RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://fieldherpers.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://fieldherpers.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://fieldherpers.snakesofarkansas.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://fieldherpers.snakesofarkansas.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.fieldherpers.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.fieldherpers.com$ [NC]

RewriteCond %{HTTP_REFERER} !^http://snakesofarkansas.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://snakesofarkansas.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.snakesofarkansas.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.snakesofarkansas.com$ [NC]


RewriteCond %{HTTP_REFERER} !^http://swaimduderanch.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://swaimduderanch.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://swaimduderanch.snakesofarkansas.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://swaimduderanch.snakesofarkansas.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.swaimduderanch.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.swaimduderanch.com$ [NC]

RewriteCond %{HTTP_REFERER} !^http://windypinesstudio.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://windypinesstudio.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://windypinesstudio.snakesofarkansas.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://windypinesstudio.snakesofarkansas.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.windypinesstudio.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.windypinesstudio.com$ [NC]

RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]


# Use mod_rewrite to enable "Clean URLs" for a PmWiki installation.
# RewriteEngine On

# The rewrite base will be the document root.
RewriteBase /

# Send requests without parameters to pmwiki.php.
RewriteRule ^$ wiki/pmwiki.php [L]

# Send requests for index.php to pmwiki.php.
RewriteRule ^index\.php$ wiki/pmwiki.php [L]

# Send requests to pmwiki.php, appending the query string part.
RewriteRule ^([^/a-z].*) wiki/pmwiki.php?n=$1 [QSA,L]

Schelly
01-08-2007, 05:54 PM
I really strongly suggest you call the support line. They had to restart Apache on the box I'm on and something about the error you're getting sounds similar somehow. Might be worth a go. You get pronto help by calling (just look at the main site Contact page) and cheerfully, politely asking 1st level rep to help. At least I did.

:)

kaptainkory
01-08-2007, 06:43 PM
I really strongly suggest you call the support line. They had to restart Apache on the box I'm on and something about the error you're getting sounds similar somehow. Might be worth a go. You get pronto help by calling (just look at the main site Contact page) and cheerfully, politely asking 1st level rep to help. At least I did.

I called. They were nice. Couldn't help. I told them someone else on the forums seemed to have a similar problem that was resolved by restarting apache on their box. Didn't seem to want to go there. Back to square one.

betiryan
01-08-2007, 06:57 PM
I called. They were nice. Couldn't help. I told them someone else on the forums seemed to have a similar problem that was resolved by restarting apache on their box. Didn't seem to want to go there. Back to square one.

They will if you call back and ask to talk to a supervisor, I don't mean they'll arbitrarilly restart the server, but the next level up of support might know a bit more about your problem.

Key to getting help, "always be POLITE!" I'm sure you are, but just wanted to mention it. :D I work in PC Support and get tired of gritting my teeth at rude, impolite, loud customers.

Beti
http://vetstribute.com

Pethens
01-08-2007, 08:33 PM
I had the same issue recently. I had a workaround (I used a file system path) so I didn't pursue it any further, but I would like the option of using this feature. It would be nice to hear from someone technical at Bluehost, although I know they don't post here very much.

kaptiankory, a workaround for you would be to call the eval function on your PHP code, something like this:

$code = file_get_contents("/path/to/code.php");
eval ($code);


See the following link for additional details you may need:
http://us2.php.net/manual/en/function.eval.php

You will also have to find some way to pass in the variables that would normally be part of the query string, but that should not be too hard to do.

Regards,

Stephen

kaptainkory
01-09-2007, 03:36 PM
I appreciate everyone's help and insight. This issue has now been resolved and the readfile() functions are working properly again. The explanation given from tech support was that this was a "temporary problem related to the firewall on the server". That's good enough for me, since some important parts of my website are now restored. The tech support was nice enough and did what they could to help me out, only it took a little deeper look to finally pin down the culprit. All is good again.