Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/01/2007, 12:15
Mais
 
Fecha de Ingreso: enero-2007
Mensajes: 6
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: Archivos xml en solo lectura

Veras el problema esque soi nuevo en esto del php y no consigo que me funcione el script.Yo creo servidor de Tibia un juego de rol el cual para las cuentas y players se necesitan archivos XML.Veras necesito que la web en php me cree el archivo XMl (Eso esta conseguido) pero en solo lectura.Es urgente, si alguien puede ayudarme porfavor responderme.
PD: Aqui os dejo el script para que le hecheis una ojeada y verais si podeis solucionarlo.
Código HTML:
$char = $_REQUEST['char'];
$char = trim($char);
$housepath = $dirdata . 'houses/';
$housefolder = opendir($housepath);
$found_house = 0;
$owner_of_house = '';
while (($housename = readdir($housefolder)) && ($found_house !== 1)) {
if ($housename == "." || $housename == "..") continue;
$temp = explode(".", $housename);
if ($temp[1] == "xml") {
$house_name = $temp[0];
$house_name2 = $housepath . $house_name . '.xml';
$open_file = fopen($house_name2, "r");
$house_contents = fread($open_file, filesize($house_name2));
$house_tags = explode("<", $house_contents);
foreach($house_tags as $house_tag) {
if (substr($house_tag, 0, 5) == "owner") {
if ($temppos = stristr($house_tag, "name=\"")) {
$temp = explode("\"", $temppos);
$owner_name = $temp[1];
if ($owner_name == ($_GET['char'])) {
$found_house = 1;
$owner_of_house = $house_name;
} 
} 
} 
} 
} 
} 
if ($owner_of_house == '') {
$owner_of_house = 'None';
} 
$guild_file = $dirdata . "guilds.xml";
$g = fopen($guild_file, "r");
$guild_contents = fread($g, filesize($guild_file));
$guild_tags = explode("<", $guild_contents);
$found = 0;
foreach($guild_tags as $guild_tag) {
if (substr($guild_tag, 0, 5) == "guild" && $found != 1) {
if ($temppos = stristr($guild_tag, "name=\"")) {
$temp = explode("\"", $temppos);
$guild_name = $temp[1];
} 
} 
if (substr($guild_tag, 0, 6) == "member") {
if ($temppos = stristr($guild_tag, "name=\"$char")) {
$temp = explode("\"", $temppos);
$member_name = $temp[1];
$found = 1;
} 
} 
} 
if ($found == 0) {
$guild_name = 'None';
} 
$guild_file = $dirdata . "guilds.xml";
$g = fopen($guild_file, "r");
$guild_contents = fread($g, filesize($guild_file));
$guild_tags = explode("<", $guild_contents);
$found = 0;
foreach($guild_tags as $guild_tag) 
{
if (substr($guild_tag, 0, 5) == "guild" && $found != 1) 
{
if ($temppos = stristr($guild_tag, "name=\"")) 
{
$temp = explode("\"", $temppos);
$guild_name = "<a href='guild.php?guild=$temp[1]'>$temp[1]</a>";
} 
}
if (substr($guild_tag, 0, 6) == "member")
{
if ($temppos = stristr($guild_tag, "name=\"$char"))
{
$temp = explode("\"", $temppos);
$member_name = $temp[1];
$found = 1;
}
}
}
if ($found == 0)
{
$guild_name = 'None';
}
$file = "$dirplayer$char.xml'r'";
$f = fsockopen("$file", "r");
if (!$char)
{
} 
else if (!$f) 
{
print("<font color=\"red\"><b>Character $char does not exist!<b></font><br><br>\n\n");
} else 
{
$contents = fread($f, filesize($file));
$tags = explode("<", $contents);
$name = "";
$id = 0;
$level = 0;
$magic_level = 0;
$voc = 0;
$town = 0;
$lastlogin = 0;
$skills = array(0, 0, 0, 0, 0, 0);
$reason = "";
$deletion = 0;
$bantime = "";
$banned = 0;
$time = "";
$namelock = 0;
foreach($tags as $tag) 
{
	    if(substr($tag, 0, 3) == "ban") {
      if($temppos = stristr($tag, "reason=\"")) {
        $temp = explode("\"", $temppos);
        $reason = $temp[1];
      }
      if($temppos = stristr($tag, "deleted=\"")) {
        $temp = explode("\"", $temppos);
        $deletion = $temp[1];
      }
      if($temppos = stristr($tag, "banrealtime=\"")) {
        $temp = explode("\"", $temppos);
        $bantime = $temp[1];
      }
      if($temppos = stristr($tag, "banned=\"")) {
        $temp = explode("\"", $temppos);
        $banned = $temp[1];
      }
   }
if (substr($tag, 0, 6) == "player") 
{
if ($temppos = stristr($tag, "name=\"")) 
{
$temp = explode("\"", $temppos);
$name = $temp[1];
} 
if ($temppos = stristr($tag, "level=\"")) 
{
$temp = explode("\"", $temppos);
$level = $temp[1];
} 
if ($temppos = stristr($tag, "id=\"")) 
{
$temp = explode("\"", $temppos);
$id = $temp[1];
} 

      if($temppos = stristr($tag, "namelock=\"")) {
        $temp = explode("\"", $temppos);
        $namelock = $temp[1];
      }
if ($temppos = stristr($tag, "maglevel=\"")) 
{
$temp = explode("\"", $temppos);
$magic_level = $temp[1];
} 
if ($temppos = stristr($tag, "voc=\"")) 
{
$temp = explode("\"", $temppos);
$voc = $temp[1];
}
if ($temppos = stristr($tag, "promoted=\"")) 
{
$temp = explode("\"", $temppos);
$promo = $temp[1];
} 
if ($temppos = stristr($tag, "sex=\"")) 
{
$temp = explode("\"", $temppos);
$sex = $temp[1];
} 
if ($temppos = stristr($tag, "lastlogin=\"")) 
{
$temp = explode("\"", $temppos);
$lastlogin = $temp[1];
} 
if ($temppos = stristr($tag, "access=\"")) 
{
$temp = explode("\"", $temppos);
$access = $temp[1];
} 
}
if (substr($tag, 0, 6) == "temple") 
{
if ($temppos = stristr($tag, "x=\"")) 
{
$temp = explode("\"", $temppos);
$town = $temp[1];
}
}
if (substr($tag, 0, 6) == "skill ") 
{
if ($temppos = stristr($tag, "skillid=\"")) 
{
$temp = explode("\"", $temppos);
$tempid = $temp[1];
} 
if ($temppos = stristr($tag, "level=\"")) 
{
$temp = explode("\"", $temppos);
$templvl = $temp[1];
} 
if ($tempid && $templvl) {
$skills[$tempid] = $templvl;
} 
} 
if (substr($tag, 0, 5) == "death") 
{ 
    if ($temppos = stristr($tag, "name=\"")) 
    { 
    $temp = explode("\"", $temppos); 
    $tempname = $temp[1]; 
    } 
 
    if ($temppos = stristr($tag, "level=\"")) 
    { 
    $temp = explode("\"", $temppos); 
    $templvl = $temp[1]; 
    }

    if ($time = stristr($tag, "time=\"")) 
    { 
    $temp = explode("\"", $time); 
    $time = $temp[1]; 
    } 

if ($time==0)
$time = "00:00";
else
$time = date ('M d Y, H:i:s',$time);
    
    if ($tempname && $templvl) 
    { 
        if (file_exists("$dirmonster$tempname.xml")) 
        { 
            $deathtext[] = " $templvl by a $tempname ($time)"; 
        } 
        elseif (file_exists("$dirplayer$tempname.xml")) 
        { 
            $deathtext[] = "$templvl by <a href=\"character.php?char=$tempname\">$tempname</a> ($time)"; 
        } 
        else 
        { 
            $deathtext[] = "$templvl by $tempname ($time)"; 
        } 
    }
}  
} 
print("<font class=block-title2><li>Character information</font></li><br><br>\n");
print("\n<table cellSpacing=1 cellPadding=4 width=450px><tr>");
print("<tr><td width=150px>Name:</td><td width=300px>$name<br/></td></tr>\n");
$charsex = array("Female", "Male");
print("<tr><td width=150px>Sex:</td><td width=300px>$charsex[$sex]<br></td></tr>\n"); 
if ($promo == 0)
$vocations = array("None", "Sorcerer", "Druid", "Paladin", "Knight");
if ($promo == 1)
$vocations = array("None", "Master Sorcerer", "Elder Druid", "Royal Paladin", "Elite Knight");
print("<tr><td width=150px>Profession:</td><td width=300px>$vocations[$voc]<br></td></tr>\n"); 
print("<tr><td width=150px>Level:</td><td width=300px>$level<br/></td></tr>\n");
print("<tr><td width=150px>Id:</td><td width=300px>$id<br/></td></tr>\n");
print("<tr><td width=150px>Magic Level:</td><td width=300px>$magic_level<br/></td></tr>\n");
print("<tr><td width=150px>World:</td><td width=300px>$worldname<br/></td></tr>\n");
if ($town == 999)
$twn = 0;
if ($town == 160)
$twn = 1;
if ($town == 355)
$twn = 2;
$towns = array("Main", "Battalion", "Arisma");
print("<tr><td width=150px>Residence:</td><td width=300px>$towns[$twn]<br/></td></tr>\n");
print("<tr><td width=150px>House:</td><td width=300px>$owner_of_house</br></td></tr>\n");
print("<tr><td width=150px>Guild membership:</td><td width=300px>$guild_name<br/></td></tr>\n");
if ($lastlogin==0)
$logindate = "Never logged in";
else
$logindate = date ('M d Y, H:i:s A',$lastlogin);
print("<tr><td width=150px>Last login:</td><td width=300px>$logindate<br/></td></tr>\n");
print("</table><br/><br/>\n");
print("<font class=block-title2><li>Account information</font></li><br><br>\n");
print("<table cellSpacing=1 cellPadding=4 width=450px><tr>");
if($bans) {
print("<br><b>Banished:</b> <br><font color=#FF0000>$bans</font><br><br>");
}
//print("<br><br>Debug<br>bann = $bann <br>deleted = $deleted<br> reason = $reason");
if($banned > 0) {
  if($deletion > 0)
print("<tr><td width=150px>Banished:</td><td width=300px><font color=red>Banished until deletion <br>because of $reason.</font><br/></td></tr>\n");
  else
print("<tr><td width=150px>Banished:</td><td width=300px><font color=red>Banished until $bantime <br>because of $reason.</font><br/></td></tr>\n");
}
$position = array("Player", "<b><font color=red>Tutor</font></b>", "<b><font color=red>Counsellor</font></b>", "<b><font color=red>Gamemaster</font></b>", "<b><font color=red>Server owner</font></b>");
print("<tr><td width=150px>Position:</td><td width=300px>$position[$access]<br></td></tr>\n");
print("</table><br/>\n");
if ($deathtext) 
{
print("\n<font class=block-title2><li>Deaths:</font><br><br>\n");
foreach($deathtext as $temp) {
}
print("<br>");
print("<tr>Killed at level $temp.<br>");
print("<br>");

//View Other Characters Script Start

print("\n<font class=block-title2><li>Characters:</font><br><br>\n");
print("<br>");
$player = $_GET['char']; 
$i = 1; 
$char_file = $dirplayer . $player . ".xml"; 
if(file_exists($char_file) && is_readable($char_file)) 
{ 
 $charXML = simplexml_load_string(file_get_contents($char_file)); 
 $acc_file = $diraccount . $charXML['account'] . ".xml"; 
 if(file_exists($acc_file) && is_readable($acc_file)) 
 { 
  $accXML = simplexml_load_string(file_get_contents($acc_file)); 
  foreach ($accXML->characters->character as $temp) 
  { 
   echo "".$i." - ".$temp['name']."<br>"; $i++; 
  } 
 } 
} 

//View Other Characters Script End
print("<br/><br/>");
} 
} 
?>