Looking how to fix this error

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Looking how to fix this error

Post by irishmike2004 »

Greetings:

A client of mine changed hosting services and one of my scripts broke. This is a straightforward script that uses the function file_get_contents($url); where url is a URL on the net.

The error when using debug

Code: Select all

function debug()
{
	ini_set('display_errors', 1);
	error_reporting(E_ALL);
}
returns this:

Warning: file_get_contents(http://del.icio.us/feeds/js/tags/handuma) [function.file-get-contents]: failed to open stream: Permission denied in /home/u3/eateam/html/deltags.php on line 24

This script works fine from both my dev machine and my personal web server on FreeBSD 6.2 and both are PHP version 5.2.4 where my client's machine is version 5.2.1 under FBSD 6.1

Hope someone can tell me how we fix this.

Thanks,

Mike
alex.w474
Forum Newbie
Posts: 3
Joined: Wed Dec 26, 2007 11:26 am

Post by alex.w474 »

The error clearly says that the file cannot be opened because of unsufficient permissions. Tell your client that the file permissions should be changed either by using telnet/ssh, control panel (cPanel) or something so.

google for cpanel change permissions, for example.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

It's probably because HTTP access through file_get_contents() is restricted by the host. Replacing the call with something based on http or curl to fetch the url would both fix the issue, and likely prevent any future issues. PEAR for example has a HTTP_Request class that could help here (if direct curl/http use is not desireable).

I think the php.ini setting for this restriction is allow_url_fopen which should be 1, but is often set to 0 on hosts.
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Post by irishmike2004 »

@maugrim:

Could you provide an example of how I would fetch the URL with the http request?

here is the full script as it sits right now:

Code: Select all

<?php

//error reporting

debug();

function debug()
{
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
}


function getDelTags($userName)
{
    //Del.icio.us User Name
    $userId = $userName;

    //limit the number of tags shown
    $limit = 25;

    //process the JS feed (TagRoll)
    $url = "http://del.icio.us/feeds/js/tags/".$userId;
    $read = file_get_contents($url);

    //run the match and build the tags array
    $match = '/"(.*?)":/';
    preg_match_all($match, $read, $tags);
    $tags = $tags[1];

    //count of the number of elements in the tags array
    $tagCount = count($tags);

    //impose the limit on the array

    if($tagCount > $limit && $limit != 0){

        $startCut = $limit -1;
        
        for($i=$tagCount;$i != $startCut;$i--){
            unset($tags[$i]);
        }
    }

    //this is a temporary echo statement to check number of tags
    //echo 'Tag Count is '.$tagCount.'<br />'; 

    //process for output
    echo '<LINK REL="StyleSheet" HREF="deltags.css" TYPE="text/css">'; //remove me when CSS is transferred to ea2007.css
    echo'<div class="delicious-tags" id="delicious-tags-'.$userId.'"><ul class="delicious-cloud">TAGS: ';

    foreach ($tags as $tag) {
        echo '<li class="delicous-tags"><a href="http://del.icio.us/'.$userId.'/'.$tag.'">'.$tag.'</a></li>';
    }

    echo '</ul></div>';
}
getDelTags(handuma);
?>
thanks for your help in advance :-)

Mike

@everyone

Thanks for the suggestions. I have gone ahead and had my client check the permissions via cpanel and the setting in PHP.INI as well.
Post Reply