@WebDevGuy posted a new topic, subject "Why isn't ini_set("allow_url_fopen", 1); working?". It read:

   I have the following code to make sure my RSS feeds work:
    
    ini_set(“allow_url_fopen”, 1);  
    if (ini_get(“allow_url_fopen”) == 1) {  
    echo “allow_url_fopen is ON”;  
    } else {  
    echo “allow_url_fopen is OFF”;  
    }
    
    Then, as you can see, I check it. It ways displays:  
    "echo “allow_url_fopen is OFF”
    
    Any ideas why?

Then @phpster said

    from the manual
    
    > allow_url_fopen boolean
    [code] 
        This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.
        
            [b]Note: This setting can only be set in php.ini due to security reasons. [/b]
        
    [/code]
    
    So you can't change it in the code

Then @WebDevGuy said

    But…
    
    http://pear.php.net/manual/en/package.xml.xml-rss.requirements.php

After which, @bokehman added

    Looks like that was not tested because if it was the author would have known it didn't work.
    
    Just out of interest why do you do this:
    [code] 
        if (ini_get("allow_url_fopen") == 1) {
        echo "allow_url_fopen is ON";
        } else {
        echo "allow_url_fopen is OFF";
        }
        
    [/code]
    
    when you could just as well do this?
    [code] 
        print ini_get("allow_url_fopen");
        
    [/code]

Then @WebDevGuy said

    ini_set(“allow_url_fopen”, 1);  
    print ini_get(“allow_url_fopen”);
    
    Prints nothing.

@bokehman replied

    That's because it is boolean(false) but print_r(ini_get(“allow_url_fopen”)); certainly would work.

To which @WebDevGuy replied

    nope, that prints nothing either. I checked and there is an entry for it in the ini file
    
    I;ve also tried:
    [code] 
         		ini_set("allow_url_fopen", 'On');
        		print_r(ini_get("allow_url_fopen"));
         		if (ini_get("allow_url_fopen") == 'On') {
        			echo "allow_url_fopen is ON";
        		} else {
        			echo "allow_url_fopen is OFF";
        		}
        
    [/code]
    
    Same thing - Off

After which, @bokehman added

    As pointed out to you above it is not possible to alter this setting from a script.

To which @WebDevGuy replied

    I appreciate you pointing that out again. I have to wonder why Pear developers wrote in the documentation that the above method should be done to overcome this that setting being set to Off. Pear developers are pretty davenportjill@example.net.
    
    http://pear.php.net/manual/en/package.xml.xml-rss.requirements.php

Then @WebDevGuy said

    I posted in the php forum but can not get a definitive answer (http://www.sitepoint.com/forums/showthread.php?t=295840)
    
    The crux of the matter is this, on Pear's XML_RSS documentation, it says that if your allow_url_fopen=Off, then ini_set it to 1:  
    http://pear.php.net/manual/en/package.xml.xml-rss.requirements.php
    
    I figure these Pear guys know what their talking about so I have tried it every which way but loose.
    
    Some people in the forum say it can't be done from code.
    
    What do you advanced PHP users say? (I have spent most of the day on this because I am trying to avoid permenently setting it to On)

@bokehman replied

    My guess is that was written without testing. Maybe the person writing it thought it would work but the truth is it certainly does not.

@WebDevGuy replied

    it certainly look sthat wya - thanks for your patience. I'm starting another thread to see if there are any security concerns with setting it to On.
    
    The SitePoint Forums
    
    ### The SitePoint Forums
    
    A community for web designers and developers to discuss everything from HTML, CSS, JavaScript, PHP, to Photoshop, SEO and more.

To which @paulyG replied

    I don't know the definitive answer, and can see how I might want to be able to do this too. Having Safe Mode set “on” in your ini may override all of your attempts though.

Then @WebDevGuy said

    how does safe_mode interact with or change allow_url_fopen?

Then @paulyG said

    As I understand it, this is because Safe mode governs whether or not you can fopen anything except in directories you have stipulated in the ini.
    
    > When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to open it.

After which, @Ezku added

    paulyG:
    
    > As I understand it, this is because Safe mode governs whether or not you can fopen anything except in directories you have stipulated in the ini.
    
    That only concerns the server directories; safe mode does not prevent you from accessing data from the outside. Edit: Then again, I could be rather wrong.

After which, @nacho added

    allow_url_fopen
    
    > Note: This setting can only be set in php.ini due to security reasons.

@seanf replied

    Threads merged. Please do not cross-post.
    
    WebDevGuy:
    
    > I posted in the php forum but can not get a definitive answer
    
    The manual says this cannot be set at script level (for obvious reasons) and your testing has proved this. Is this not a definitive answer?
    
    Sean

To which @paulyG replied

    http://www.bigbold.com/snippets/posts/show/530
    
    Is this workaround any help?

@system replied

    


{'source': 'discourse', 'url': 'https://www.sitepoint.com/community/t/why-isnt-ini-set-allow-url-fopen-1-working/2174', 'title': 'Why isn\'t ini_set("allow_url_fopen", 1); working?', 'views': 40129, 'has_accepted_answer': False, 'word_count': 761, 'like_count': 0, 'reply_count': 6, 'participant_count': 7, 'posts': 20, 'tags': '', 'author': '@WebDevGuy', 'participants': '@WebDevGuy, @phpster, @bokehman, @paulyG, @Ezku, @nacho, @seanf, @system', 'image_url': [None], 'created_at': '2005-09-01T18:16:02.000Z', 'last_posted_at': '2014-10-08T00:33:26.266Z'}