Jump to content

Recommended Posts

Posted

PHP's file_get_contents() isn't working properly on Stevie. It's been working fine since I started hosting here, but just stopped yesterday. If I use file_get_contents() to retrieve something else that's on my own domain, it fails. It works fine if I request something not located on my domain, such as Google's website.

 

file_get_contents("http://raxsoft.tk/raxdev/sbt/sb.php?b=105");

That code should return an image, but instead returns false. A request where the target is on my own domain will fail. If you view the targeted URL in a browser, it loads fine, so the resource isn't the problem. This exact command worked yesterday, but now fails for an unknown reason.

 

file_get_contents("http://google.com") returns HTML for google as expected.

 

Here's a test script that shows the issue: http://raxsoft.tk/ra...sbt/testget.php If it works, you'll see an American flag with a countdown to July 4th next year. If it fails, it'll say so.

 

Anyone have an idea why this is happening? (raxsoft.tk, user rax on Stevie)

Posted

This would never return an image:

 

file_get_contents("http://raxsoft.tk/raxdev/sbt/sb.php?b=105");

 

It would try to return the contents. Evidently your browser was interpreting the source as the image.

Don't forget you need to echo it out:

 

<?php
$src = file_get_contents("http://raxsoft.tk/raxdev/sbt/sb.php?b=105");
echo $src;
?>

 

I just tried a couple of tests on my site and it was working fine.

 

 

Posted

Well yes. I meant the contents of an image (binary data). It is echoed out. My test script is like yours, except it has an if statement to check that $src has data and not false in it. The problem is in my case the image content is never read. In your example code, $src is false(meaning the get failed) instead of the image data once the file_get_contents runs. Echoing false doesn't do anything useful...

 

I'll try a few other things, but I'm stumped as to why this just quit working on Friday...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...