• GoDaddy Community
  • Websites + Marketing | Website Builders
  • Websites + Marketing | Website Builders

    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution

    PHP file_get_contents doesnt work

    file_get_contents doesnt work from godaddy's hosting. However the same code works from localhost. i tried CURL_EXEC but got the same problem. It seems like hosting parameters do not allow working with external URL's. Anyone familiar with this kind of problem? Cannot send POST or GET request to any resource. Here is very simple example that doesnt work 



    function curl_get($url, array $get = NULL, array $options = array())
    $defaults = array(
    CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),

    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if( ! $result = curl_exec($ch))
    return $result;

    2 REPLIES 2
    Former Employee

    Re: PHP file_get_contents doesnt work

    Hi Aaron,


    You may need to change the php options in your cPanel account. I would double check these settings through the Select PHP Version in cPanel.


    If you follow this guide, it should walk you through the process: https://www.godaddy.com/help/view-or-change-your-php-version-16090?


    And once on that Select PHP Version page, click on the Switch to PHP Options writing in the top right of that page, you should be able to review what php modules are currently activated.


    Hope this helps!


    Re: PHP file_get_contents doesnt work

    Hello Aaron,
    Recently had the same issue with the (file_get_contents) not working. 
    I have 3 C Panels with godaddy and use one of them as a tester and trouble shooter. 
    What i found to enable this, 
    - Goto the Homepage of the CPanel, 
    - Scroll down to "Select PHP Version"

    Now, This will show your php version as well as the file extensions that your cpanel will be using. 
    I am currently using PHP 7.1,   Really should not matter if you are using a different version. 
    Next click on the link at the top right corner that says. "Switch to PHP Options"

    image 1.png

    After clicking the blue link at the top right corner, this will give you a couple features and settings you can adjust. The ones that you need to make sure are set to "ON" will be highlighted in the image below. 

    Allow_URL_fopen = On

    Short_open_Tag = On

    image 2.png

    Please Note, the black lines are for security purposes towards the CPanel and should not be shared to the public.  The Green Lines are the ones you need to look at and to verify if they are set to "ON" or "OFF"   So make sure both of them are set to "ON".

    Hope this helps!