- Forums
- PHP
- File_get_contents() Function Is Not Working In Php
on this page i will give you and example as to why my file_get_contents() function is not working in PHP and what i did to fix this issue [1305], Last Updated: Sat May 18, 2024
wallpaperama
Sun Mar 11, 2012
0 Comments
332 Visits
hi everyone, just wanted to share something with you today about file_get_contents().
i was trying to get some data from a url and it was not working, i was not getting anything back. this is what i found out. the url i was trying to get the information was not resolving correctly. in other words, i was running my script from a server which had the same ip address from the same server i was running the script but the domain was hosted on another server so be sure to check your hosts file to be sure the domain is not resolving somewhere it shouldnt.
for example, i wanted the output of this url:
http://www.example.com/time.php
the output was: 5:40pm
this is how the script looked like:
<?php
$Url = 'http://www.example.com/time.php';
echo 'The time is: '.$Url;
?>
when i ping example.com was going to a different ip address my domain was being hosted. so i had to chang my hosts in my control panel of hosting domain names on the server i was running the script.