+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP Error File Access Error, Help Please.

  1. #1
    MerCiLeSS is offline x10Hosting Member MerCiLeSS is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    6

    Angry PHP Error File Access Error, Help Please.

    PHP Code:
    <?
    $output 
    "http://merciless.pcriot.com/index.html";

    function 
    FetchRanks($url) {
    $filepointer fopen($url,"r");

    if(
    $filepointer){
        while(!
    feof($filepointer)){
            
    $buffer fgets($filepointer4096);
            
    $file .= $buffer;
        }
        
        
    fclose($filepointer);

    } else {
        die(
    "Could not create a connection to the Last Chaos website.");
    }


    $pattern "/<tr><td class=\"rank\">(.*)<\/td><td class=\"rank-charname\">(.*)<\/td><td class=\"rank-charlevel\">(.*)<\/td><td class=\"rank-guild\">(.*)<\/td><\/tr>/iU";

    preg_match_all($pattern$file$playersPREG_SET_ORDER);

    $guilds = array();
    foreach (
    $players as $player) {
        
        
    //Catch guidless
        
    $player[4] == '' $player[4] = "(guildless)" 0;

        
    //Top 10.
        
    $player[1] <= 10 $tmptop $player[3] : $tmptop 0;
        
    $player[1] <= 10 $tmpin $tmpin 0;
        
        
    //9x or 10x
        
    $player[3] >= 90 && $player[3] <= 99 $tmp9x $tmp9x 0;
        
    $player[3] >= 100 $tmp10x $tmp10x 0;
        
        
    //9x & 10x totals
        
    $player[3] >= 90 && $player[3] <= 99 $tmp9xtot $player[3] : $tmp9xtot 0;
        
    $player[3] >= 100 $tmp10xtot $player[3] : $tmp10xtot 0;

        
    //New guild, add to array
        
    if ($player[4] != '' && !array_key_exists($player[4], $guilds)) {
            
    $guilds[$player[4]] = array("top50" => $player[3], "top10" => $tmptop"in50" => 1"in10" => $tmpin"9x" => $tmp9x"10x" => $tmp10x"9xtot" => $tmp9xtot"10xtot" => $tmp10xtot);

        
    //Guild already in array, add player stats to guild array
        
    } elseif ($player[4] != '') {
            
    $guilds[$player[4]]['top50'] = $guilds[$player[4]]['top50'] + $player[3];
            
    $guilds[$player[4]]['in50'] = $guilds[$player[4]]['in50'] + 1;
            
            
    $guilds[$player[4]]['top10'] = $guilds[$player[4]]['top10'] + $tmptop;
            
    $guilds[$player[4]]['in10'] = $guilds[$player[4]]['in10'] + $tmpin;
            
            
    $guilds[$player[4]]['9x'] = $guilds[$player[4]]['9x'] + $tmp9x;
            
    $guilds[$player[4]]['9xtot'] = $guilds[$player[4]]['9xtot'] + $tmp9xtot;
            
            
    $guilds[$player[4]]['10x'] = $guilds[$player[4]]['10x'] + $tmp10x;
            
    $guilds[$player[4]]['10xtot'] = $guilds[$player[4]]['10xtot'] + $tmp10xtot;
            
        }
    }

    foreach (
    $guilds as $key => $row) {
        
    $row['9xtot'] != ? ($guilds[$key]['avg9x'] = round($row['9xtot'] / $row['9x'])) : 0;
        
    $row['10xtot'] != ? ($guilds[$key]['avg10x'] = round($row['10xtot'] / $row['10x'])) : 0;
        
    $guilds[$key]['pt50'] = round(($row['in50'] / 300) * 1002);
        
    $guilds[$key]['pt10'] = round(($row['in10'] / 60) * 1002);
    }

    foreach (
    $guilds as $key => $row) {
        
    $top50[$key] = $row['top50'];
        
    $top10[$key] = $row['top10'];
    }

    array_multisort($top50SORT_DESC$top10SORT_DESC$guilds);

    //Build table
    $pos 0;
    $rvalue '';
    foreach (
    $guilds as $guild => $data) {

        if (
    $guild != '(guildless)') {
            
    $pos++;
        
            
    $rvalue $rvalue."<tr>\n";
            
    $rvalue $rvalue."<td>{$pos}</td>\n";
            
    $rvalue $rvalue."<td class=\"guildtd\">{$guild}</td>\n";
            
    $rvalue $rvalue."<td>{$data['top50']}<br /><font>Players: {$data['in50']} ({$data['pt50']}%)</font></td>\n";
            
    $data['top10'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$data['top10']}<br /><font>Players: {$data['in10']} ({$data['pt10']}%)</font></td>\n";
            
    $data['9x'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$data['9x']}<br /><font>Average: {$data['avg9x']}</font></td>\n";
            
    $data['10x'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$data['10x']}<br /><font>Average: {$data['avg10x']}</font></td>\n";
            
    $rvalue $rvalue."</tr>\n";            
        }
    }

    if (
    array_key_exists('(guildless)'$guilds)) {
        
    $rvalue $rvalue."<tr>\n";
        
    $rvalue $rvalue."<td>&nbsp;</td>\n";
        
    $rvalue $rvalue."<td class=\"guildtd\"><em>(guildless)</em></td>\n";
        
    $rvalue $rvalue."<td>{$guilds['(guildless)']['top50']}<br /><font>Players: {$guilds['(guildless)']['in50']} ({$guilds['(guildless)']['pt50']}%)</font></td>\n";
        
    $guilds['(guildless)']['top10'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$guilds['(guildless)']['top10']}<br /><font>Players: {$guilds['(guildless)']['in10']} ({$guilds['(guildless)']['pt10']}%)</font></td>\n";
        
    $guilds['(guildless)']['9x'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$guilds['(guildless)']['9x']}<br /><font>Average: {$guilds['(guildless)']['avg9x']}</font></td>\n";
        
    $guilds['(guildless)']['10x'] <= $rvalue $rvalue."<td>-</td>\n" $rvalue $rvalue."<td>{$guilds['(guildless)']['10x']}<br /><font>Average: {$guilds['(guildless)']['avg10x']}</font></td>\n";
        
    $rvalue $rvalue."</tr>\n";
    }
    return 
    $rvalue;
    }

    $header = <<<HEAD
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Unofficial Last Chaos USA Guild Rankings</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <br />
    <img src="header.jpg" alt="Guild Rankings" />
    <br />
    <strong>Server:</strong>&nbsp;&nbsp;<a href="#Katar">Katar</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#Cariae">Cariae</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#Sarissa">Sarissa</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#Hatzring">Hatzring</a>
    <br />
    HEAD;

    $servhead = <<<SERVHEAD
    <br />
    <h1 id="*NAME*">*NAME*</h1>
    <font>Updated: *DATE*</font>
    <br /><br />
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th scope="col">&nbsp;</th>
        <th scope="col">Guild</th>
        <th scope="col">Top 50</th>
        <th scope="col">Top 10</th>
        <th scope="col">Lvl. 9x</th>
        <th scope="col">Lvl. 10x</th>
      </tr>
    SERVHEAD;

    $footer "</body>\n</html>";

    $katar str_replace(array("*NAME*""*DATE*"), array("Katar"date("Y-m-d H:i:s T")), $servhead).FetchRanks("http://lastchaos.aeriagames.com/community/rankings")."</table><br />\n";

    $cariae str_replace(array("*NAME*""*DATE*"), array("Cariae"date("Y-m-d H:i:s T")), $servhead).FetchRanks("http://lastchaos.aeriagames.com/community/rankings/active/Cariae")."</table><br />\n";

    $sarissa str_replace(array("*NAME*""*DATE*"), array("Sarissa"date("Y-m-d H:i:s T")), $servhead).FetchRanks("http://lastchaos.aeriagames.com/community/rankings/active/Sarissa")."</table><br />\n";

    $hatzring str_replace(array("*NAME*""*DATE*"), array("Hatzring"date("Y-m-d H:i:s T")), $servhead).FetchRanks("http://lastchaos.aeriagames.com/community/rankings/active/Hatzring")."</table><br />\n";

    $handle fopen($output'w');

    fwrite($handle$header.$katar.$cariae.$sarissa.$hatzring.$footer);
    fclose($handle);

    ?>
    And it gives me this error...


    Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/merciles/public_html/lc.php on line 5

    Warning: fopen(http://lastchaos.aeriagames.com/community/rankings) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/merciles/public_html/lc.php on line 5
    Could not create a connection to the Last Chaos website.


    Any help would be great!

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Error File Access Error, Help Please.

    If you're using PHP Level 1 (Basic), then you would have to upgrade to Level 2 (Intermediate). The PHP configuration is more lenient about these kind of things.

    On a side note, although this has nothing to do with your problem, it's recommended that you open php tags with <?php as opposed to the short-handed (lazy) way <?

  3. #3
    MerCiLeSS is offline x10Hosting Member MerCiLeSS is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    6

    Re: PHP Error File Access Error, Help Please.

    solved for now, after r-reading lvl 1 has no fopen. I submitted for upgrade to lvl 2... hope it goes fast

    Edit: They already accepted my request, its pending upgrade now... Very fast! Almost makes me wanna move up to a payed acct :o
    Edit:
    Warning: fopen(http://merciless.pcriot.com/index.html) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections in /home/merciles/public_html/lc.php on line 151

    Warning: fwrite(): supplied argument is not a valid stream resource in /home/merciles/public_html/lc.php on line 153

    Warning: fclose(): supplied argument is not a valid stream resource in /home/merciles/public_html/lc.php on line 154
    bleh.
    Last edited by MerCiLeSS; 10-22-2008 at 09:15 PM. Reason: Automerged Doublepost

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Error File Access Error, Help Please.

    You cannot write to a file that's contained in a url. It's best to set $output to the absolute location of index.html, as a relative location is kinda hit and miss (at least for me, since I don't play w/ it that much)... For example, /home/merciless/public_html/index.html . I don't know if that's the location to your index.html file, but as I said before, you cannot write to a file located outside of your folder heiarchy for lack of a better word.

  5. #5
    MerCiLeSS is offline x10Hosting Member MerCiLeSS is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    6

    Re: PHP Error File Access Error, Help Please.

    Yep, thanks man!

    O_O
    Last edited by MerCiLeSS; 10-22-2008 at 09:49 PM. Reason: Automerged Doublepost

  6. #6
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Error File Access Error, Help Please.

    Well that's odd... maybe it's got something to do with file permissions? It's possible that it is writing it with 660 or 640 permissions as opposed to 644, but I wouldn't know why...
    Last edited by xPlozion; 10-22-2008 at 09:50 PM.

  7. #7
    MerCiLeSS is offline x10Hosting Member MerCiLeSS is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    6

    Re: PHP Error File Access Error, Help Please.

    Its working now, im just attempting to move the Swap the Katar and Cariae ranks. It's putting Katar's rank table first, giving me hell switching it.

    Also, what would the cronjob command be to make it hit http://merciless.pcriot.com/lc.php twice a day?
    Last edited by MerCiLeSS; 10-22-2008 at 10:05 PM.

  8. #8
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Error File Access Error, Help Please.

    To be honest, I would not know. I never was good at setting cronjobs for PHP in CPanel. I can set them on my computer to run tasks and the such, but I haven't been able to do anything like that on cpanel... I'll look into it though...

    looking through google, the first result came up with a hit

    try:
    Code:
    php /home/serverpath/script/file.php
    Source: http://www.webmasterworld.com/forum88/6102.htm
    Last edited by xPlozion; 10-22-2008 at 10:17 PM.

  9. #9
    MerCiLeSS is offline x10Hosting Member MerCiLeSS is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    6

    Re: PHP Error File Access Error, Help Please.

    Doesnt seem to work, even with -q flag... going to sleep now tho.

    Thanks!

  10. #10
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: PHP Error File Access Error, Help Please.

    Here's an (almost) copy and paste from mine:
    Code:
    php -q /home/salvatos/etc/file.php
    Just replace salvatos with your own user and /etc with whatever your filepath is.
    As an advice, make sure your file can't be accessed by typing in the URL, 'cause then anyone could do the equivalent of your cron job by simply visiting the page.

    And since "Every twelve hours" is not in the dropdown list in the Standard editor, you'll need to go the the advanced one set it like this : 0 */12 * * *

    Hope that works.

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. Places to learn php
    By JaWasabi in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 01-13-2009, 02:03 AM
  3. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM
  4. php problem
    By himgar in forum Free Hosting
    Replies: 1
    Last Post: 02-22-2008, 02:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers