Please help with file_get_contents

Good afternoon, sorry for the inconvenience caused but I need to see if you can help me. I am hosting a website which will contain a link example version.php which users who have the script using
file_get_contents get the content of that link which will be the version but the problem is that it seems that infinity free has it blocked could you help me see how I can get users to use
file_get_contents to my web. Thanks

can you post the line of your php code so I can take a look, thanks

oh and please click the
image
code icon and paste it in there so that the code is displayed correctly

thanks

$version = @file_get_contents('http://crhinet.rf.gd/version.php', 0, stream_context_create(["http"=>["timeout"=>1]]));
        echo $version;

It should show v2.1 but it doesn’t show anything

ive just run a test on my website https://lovebyte.eu.org/test/file_get_contents.php

and this is the code I used

<?php echo file_get_contents($_SERVER['DOCUMENT_ROOT'].'/test/testdata.txt'); ?>

You cannot load files from URLs through that function here as it is disabled for security reasons, you can either fetch it through functions such as curl or directly access it if it is hosted on the same site.

4 Likes

yes friend but that code is for local what I want is for the users to do it from a script that I pass them the code works correctly because I try it on my network and it works but with the host I was not reading the forum posts and they said They have suspended the function to the infinityfree server and I want to see if you can help me to allow it or in some other way

i have used file_get_contents with a url on my servers.php page and it does read the contents correctly but in my case im pulling the data from my home server and havent tried it with my webhost as a url

this is the code i used

<?php
			$serverlist = file_get_contents('http://lovebug.servegame.com:32767/serverInfo.html');
			if ( $serverlist === false )
			{
			echo '<h3>Sorry, the servers are offline<br><br>I will restore them as soon as I can.</h3>';
			}
			else
			{
			echo $serverlist;
			}
			?>
1 Like

yeah I just altered my test page to use my domain url and got an error

1 Like

@Crhistopher alter your code to this and it should work

$version = @file_get_contents($_SERVER['DOCUMENT_ROOT'].'/version.php', 0, stream_context_create(["http"=>["timeout"=>1]]));
        echo $version;
3 Likes

Any programmatic access to data on your website hosted with us is not possible due to a security system we use:

What to do next depends on why you need to fetch it in the first place.

If you want to fetch it from your own site, you’ll probably want to just require or include the PHP code so it runs in the same request (meaning it’s much faster).

If it needs to be access from other sites, you need to find another solution for this. For example by pushing the latest version to another system, instead of generating it with PHP on the fly.

8 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.