PHP Error File Access Error, Help Please.

MerCiLeSS

New Member
Messages
6
Reaction score
0
Points
0
PHP:
<?
$output = "http://merciless.pcriot.com/index.html";

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

if($filepointer){
    while(!feof($filepointer)){
        $buffer = fgets($filepointer, 4096);
        $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, $players, PREG_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 = 1 : $tmpin = 0;
    
    //9x or 10x
    $player[3] >= 90 && $player[3] <= 99 ? $tmp9x = 1 : $tmp9x = 0;
    $player[3] >= 100 ? $tmp10x = 1 : $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'] != 0 ? ($guilds[$key]['avg9x'] = round($row['9xtot'] / $row['9x'])) : 0;
    $row['10xtot'] != 0 ? ($guilds[$key]['avg10x'] = round($row['10xtot'] / $row['10x'])) : 0;
    $guilds[$key]['pt50'] = round(($row['in50'] / 300) * 100, 2);
    $guilds[$key]['pt10'] = round(($row['in10'] / 60) * 100, 2);
}

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

array_multisort($top50, SORT_DESC, $top10, SORT_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'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$data['top10']}<br /><font>Players: {$data['in10']} ({$data['pt10']}%)</font></td>\n";
        $data['9x'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$data['9x']}<br /><font>Average: {$data['avg9x']}</font></td>\n";
        $data['10x'] <= 0 ? $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'] <= 0 ? $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'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$guilds['(guildless)']['9x']}<br /><font>Average: {$guilds['(guildless)']['avg9x']}</font></td>\n";
    $guilds['(guildless)']['10x'] <= 0 ? $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!
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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 <?
 

MerCiLeSS

New Member
Messages
6
Reaction score
0
Points
0
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 :eek:
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:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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.
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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:

MerCiLeSS

New Member
Messages
6
Reaction score
0
Points
0
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:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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:

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
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.
 
Top