Extracting data from XML sheet with PHP

Discussion in 'General Webmaster Support' started by TFlan, Jun 10, 2007.

  1. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    i cant seem to figure this one out...

    if i have this for xml:

    Code:
    <taghere attributename="value" anothername="value1" />
    how do i get it so i can assign to a php value
    Code:
    $value = attributename;
     
  2. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    Which PHP version are you using and what exactly are you up to?

    • For large documents processed as a stream, use the SAX-based API functions. You'll find some more or less useful examples in this thread from: www.php.net.
    • For smaller things or when you have to jump back and forth between elements, there's XML DOM. Note that the API changed between PHP 4 and PHP 5.
    • There's more, like SimpleXML or XMLReader / XMLWriter.
    • Don't use some weird preg_match() constructs, as you'll have to do proper charset conversion and entity decoding.
    Note that you definately don't want to set $myAttr based on attributename="myAttr", as bad things(TM) will happen on user-fed documents without toroughful input validation.

    Brain-dead example using PHP5 DOM, without any sanity checks:
    Code:
    <?php
    
    $xml = new DOMDocument();
    $xml->loadXML('<taghere attributename="value" anothername="value1" />');
    
    $elems = $xml->getElementsByTagName('taghere');
    foreach ($elems as $elem)
    {
      print $elem->getAttribute('attributename'). ' = ' . $elem->getAttribute('anothername') . "\n";
    }
    
    ?>
     
    • Like Like x 1
  3. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    Thank-you, but when i go to test this:

    Code:
    Warning: domdocument() expects at least 1 parameter, 0 given in
    (address here) on line 5
    
    Fatal error: Call to undefined function: loadxml() in
    (address here) on line 6
    Those errors are found on:

    PHP:
    $xml = new DOMDocument();
    $xml->loadXML('test.xml');
    EDIT:

    This may be why

    "PHP Version 4.4.0" -phpinfo();
     
  4. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    As this example shows, the day you're forced to upgrade to PHP5 or later, you'll have a lot of fun. Or just call it defective by design.

    On a side note: if I were you, I'd choose another language for your website or whatever you're messing around with. That'd spare you quite a few potential security breaches, given you're running a pretty old release 4.4.0 (unless security patches have been backported?). If you really want to stick with PHP, add at least Stefan Esser's Suhosin hardening patches and extension: http://www.hardened-php.org/suhosin.127.html

    Here's the same brain-dead code as above, but backported to PHP4:
    PHP:
    <?php

    $xml 
    domxml_open_mem('<taghere attributename="value" anothername="value1" />');

    $elems $xml->get_elements_by_tagname('taghere');
    foreach (
    $elems as $elem)
    {
      print 
    $elem->get_attribute('attributename'). ' = ' $elem->get_attribute('anothername') . "\n";
    }

    ?>
     
  5. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    omg i cant figure this out for the life of me... ive been at php.net for the past couple hours trying to figure it out...

    PHP:
    function GetRoster(){
        
    $roster_front "<table><tr><td>Name</td><td>Level</td><td>Class</td><td>Race</td><td>Gender</td><td></td></tr>";
        
    $xml domxml_open_file("http://armory.worldofwarcraft.com/guild-info.xml?r=Lightning's+Blade&n=Paradigm+Shift");
        
    $elems $xml->get_elements_by_tagname('characters');
        foreach (
    $elems as $elem){
            
    $name $elem->get_attribute('name');
            
    $level $elem->get_attribute('level');
            
    $class $elem->get_attribute('class');
            
    $race $elem->get_attribute('race');
            
    $gender $elem->get_attribute('gender');
            
    $url $elem->get_attribute('url');
             
    $roster_front .= "<tr><td>$name</td><td>$level</td><td>$class</td><td>$race</td><td>$gender</td><td><a href='http://armory.worldofwarcraft.com/character-sheet.xml?$url'>Armory</a></td></tr>";
        } 
        
    $roster_front .= "</table>";
        return 
    $roster_front;
    }
    i get these errors:

    Code:
    Warning: domxml_open_file(): ParsePI: PI xml-stylesheet never end ... in /home/www/theugl.com/functions/functions.php on line 5
    
    Warning: domxml_open_file(): Start tag expected, '<' not found in /home/www/theugl.com/functions/functions.php on line 5
    
    Fatal error: Call to a member function on a non-object in /home/www/theugl.com/functions/functions.php on line 6
    for the second warning i dont know what the hell its talking about...
     
  6. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    It's pretty obvious, you only have to read the error messages and look at your code:

    1. fetch the XML file using a HTTP GET (cURL or whatever your favorite is) and not directly from the DOMXML code and switch to domxml_opem_mem() instead. Someone might turn off fopen_wrappers and you'll look stupid. Or it's already disabled, which would be good choice.
    2. (optional, may work find with the XSL stylesheet) remove the stylesheet from XML file, or tell PHP to ignore external entities
    3. once that works, you'll get another error. Try fetching character instead of characters in get_elements_by_tagname()
     
  7. mase

    mase ____ ___ ____ __

    Ratings:
    +155 / 0 / -0
    Lol, are you sure you want to be opening Blizzard's xml files and listing the roster? You could be IP banned if someone spams it.
     
  8. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    Im using domxml_opem_mem(), looked up the cURL, i have never even heard of that library before :confused:, i need some help there.

    Ok, i found how to do it with php5, which my server isn't upgrading to yet..., but i can't find it on php4 :/

    thanks for the help so far :D
     
  9. DDRtists

    DDRtists ɹoʇɐɹǝpoɯ ɹǝdns Staff Member

    Ratings:
    +413 / 0 / -0
    Yeah, I don't think you'll want to be opening Blizzards XML files. :eek:
     
  10. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    Now what about this :D :
    PHP:
    <?php

    $url 
    'http://armory.worldofwarcraft.com/guild-info.xml?r=Lightning\'s+Blade&n=Paradigm+Shift';

    header('Content-type: text/plain');

    # -------------------------------------
    # fetch $url using either cURL or fopen
    # -------------------------------------
    if (function_exists('curl_init'))
    {
        
    # curl_* functions are available
        
    print "[+] cURL is installed. Using it.\n";
        if ((
    $handle curl_init($url)) === false)
        {
            print 
    "[-] curl_init() failed\n";
            exit;
        }
        
    curl_setopt($handleCURLOPT_HEADER0);
        
    curl_setopt($handleCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($handleCURLOPT_RETURNTRANSFER1);

        if ((
    $content curl_exec($handle)) === false)
        {
            print 
    "[-] curl_exec() failed\n";
            
    curl_close($handle);    
            exit;
        }
        
    curl_close($handle);    
    }
    else if (
    is_resource($handle fopen($url'r')))
    {
        
    # revert to fopen()
        
    print "[+] Using fopen_wrapper\n";
        
    $content '';
        while(!
    feof($handle))
        {
            if ((
    $tmp fread($handle4096)) === false)
            {
                print 
    "[-] fread() failed\n";
                
    fclose($handle);    
                exit;
            }
            
    $content .= $tmp;
        }
        
    fclose($handle);    
    }
    else if (
    function_exists('fsockopen'))
    {
        print 
    "[+] Using fsockopen()\n";
        if (!
    preg_match(',http://(.*?)(/.*),'$url, &$matches))
        {
            print 
    '[-] Invalid $url: ' $url "\n";
            exit;
        }

        if (!(
    $handle fsockopen($matches[1], 80)))
        {
            print 
    "[-] fread() failed\n";
            exit;
        }

        
    $request 'GET ' $matches[2] . ' HTTP/1.1' "\n"
        
    'Host: ' $matches[1] . "\n"
        
    'Connection: close' "\n\n";

        
    $len strlen($request);
        if (
    fwrite($handle$request$len) != $len)
        {
            print 
    "[-] fwrite() couldn't send the data\n";
            exit;
        }
        
    fflush($handle);

        
    $content '';
        while(!
    feof($handle))
        {
            if ((
    $tmp fread($handle4096)) === false)
            {
                print 
    "[-] fread() failed\n";
                
    fclose($handle);    
                exit;
            }
            
    $content .= $tmp;
        }
        
    fclose($handle);    

        if ((
    $pos strpos($content"\n\n")) === false && ($pos strpos($content"\r\n\r\n")) === false)
        {
            print 
    "[-] HTTP response header not found\n";
            exit;
        }

        
    $content substr($content$pos);
    }
    else
    {
        
    # better try something else...
        
    print "[-] Bad luck, neither cUrl, fsockopen() nor fopen_wrapper available\n";
        exit;
    }

    # ---------------------------
    # parse $content using DOMXML
    # ---------------------------
    if (($xml domxml_open_mem($content)) == false)
    {
        print 
    "[-] domxml_open_mem() failed\n";
        exit;
    }

    $elems $xml->get_elements_by_tagname('character');
    if (empty(
    $elems))
    {
        print 
    "[-] No elements available.\n";
        exit;
    }

    print 
    "[+] Output:\n";
    foreach (
    $elems as $elem)
    {
        print 
    'Name:    ' $elem->get_attribute('name') . "\n"
        
    'Level:    ' $elem->get_attribute('level') . "\n"
        
    'Class:    ' $elem->get_attribute('class') . "\n"
        
    'Race:     ' $elem->get_attribute('race') . "\n"
        
    'Gender: ' $elem->get_attribute('gender') . "\n"
        
    'Url:        ' $elem->get_attribute('url') . "\n\n";
    }

    ?>
     
    • Like Like x 1
  11. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    wow! (+rep on that one)

    I love it, but...

    Code:
    [+] cURL is installed. Using it.
    <br />
    <b>Warning</b>:  domxml_open_mem(): ParsePI: PI xml-stylesheet never end ...
     in ... on line <b>105</b><br />
    <br />
    <b>Warning</b>:  domxml_open_mem(): Start tag expected, '&lt;' not found
     in ... on line <b>105</b><br />
    [-] domxml_open_mem() failed
    Lines its talking about, but i think you know from this:

    Code:
    [-] domxml_open_mem() failed
    here is the php

    PHP:
    if (($xml domxml_open_mem($content)) == false)
    {
        print 
    "[-] domxml_open_mem() failed\n";
        exit;
    }

    ---------

    @ DDRtists
    Oh but i do!!! Plus this will give me insight on how to use XML inside PHP, which is a big bonus :D
     
  12. DDRtists

    DDRtists ɹoʇɐɹǝpoɯ ɹǝdns Staff Member

    Ratings:
    +413 / 0 / -0
    You're going to get your IP banned if you open it too many times. :p
     
  13. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    Nice one, Blizzard. :rolleyes:
    Maybe I should have tested on the live system, rather than a local copy of the XML save.

    Working solution in a few minutes. The webserver doesn't return you XML, but plain HTML.
     
  14. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    i can always put in a timer, allowing it to open once a day, and every 24 hours save the Armory XML to an XML sheet on my server and just pull the info off of that.

    problem solved :D

    -----
    EDIT:
    -----

    Source from link http://armory.worldofwarcraft.com/guild-info.xml?r=Lightning's+Blade&n=Underworld

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="/layout/guild-info.xsl"?>
    
    <page globalSearch="1" lang="en_us" requestUrl="/guild-info.xml">
      <guildInfo>
        <guild battleGroup="Vindication" name="Underworld" realm="Lightning's Blade" rosterUrl="r=Lightning%27s+Blade&amp;n=Underworld&amp;p=1" statsUrl="r=Lightning%27s+Blade&amp;n=Underworld" statsUrlEscape="r=Lightning%27s+Blade&amp;n=Underworld">
          <members memberCount="49">
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="47" name="Acillatem" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Acillatem"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Amaha" race="Tauren" raceId="6" rank="1" url="r=Lightning%27s+Blade&amp;n=Amaha"/>
            <character class="Shaman" classId="7" gender="Male" genderId="0" level="70" name="Asakhar" race="Orc" raceId="2" rank="3" url="r=Lightning%27s+Blade&amp;n=Asakhar"/>
            <character class="Warlock" classId="9" gender="Male" genderId="0" level="48" name="Bloodi" race="Blood Elf" raceId="10" rank="3" url="r=Lightning%27s+Blade&amp;n=Bloodi"/>
    
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="46" name="Bloodmaniak" race="Blood Elf" raceId="10" rank="4" url="r=Lightning%27s+Blade&amp;n=Bloodmaniak"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="20" name="Clockradio" race="Tauren" raceId="6" rank="4" url="r=Lightning%27s+Blade&amp;n=Clockradio"/>
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="60" name="Cooldowns" race="Blood Elf" raceId="10" rank="3" url="r=Lightning%27s+Blade&amp;n=Cooldowns"/>
            <character class="Priest" classId="5" gender="Female" genderId="1" level="66" name="Curranhealz" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Curranhealz"/>
            <character class="Warlock" classId="9" gender="Male" genderId="0" level="70" name="Deathwishh" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Deathwishh"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="45" name="Diablomaniak" race="Blood Elf" raceId="10" rank="4" url="r=Lightning%27s+Blade&amp;n=Diablomaniak"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="25" name="Doesitmatter" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Doesitmatter"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="70" name="Eofk" race="Tauren" raceId="6" rank="1" url="r=Lightning%27s+Blade&amp;n=Eofk"/>
            <character class="Warlock" classId="9" gender="Male" genderId="0" level="70" name="Fearfigment" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Fearfigment"/>
    
            <character class="Hunter" classId="3" gender="Male" genderId="0" level="11" name="Fokd" race="Tauren" raceId="6" rank="4" url="r=Lightning%27s+Blade&amp;n=Fokd"/>
            <character class="Hunter" classId="3" gender="Male" genderId="0" level="70" name="Foldeak" race="Blood Elf" raceId="10" rank="3" url="r=Lightning%27s+Blade&amp;n=Foldeak"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Froggert" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Froggert"/>
            <character class="Priest" classId="5" gender="Male" genderId="0" level="70" name="Ghostmaniak" race="Blood Elf" raceId="10" rank="1" url="r=Lightning%27s+Blade&amp;n=Ghostmaniak"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Grogol" race="Tauren" raceId="6" rank="1" url="r=Lightning%27s+Blade&amp;n=Grogol"/>
            <character class="Paladin" classId="2" gender="Male" genderId="0" level="70" name="Halomaniak" race="Blood Elf" raceId="10" rank="1" url="r=Lightning%27s+Blade&amp;n=Halomaniak"/>
            <character class="Paladin" classId="2" gender="Male" genderId="0" level="25" name="Herthnbuble" race="Blood Elf" raceId="10" rank="4" url="r=Lightning%27s+Blade&amp;n=Herthnbuble"/>
            <character class="Priest" classId="5" gender="Male" genderId="0" level="70" name="Hippoboy" race="Troll" raceId="8" rank="4" url="r=Lightning%27s+Blade&amp;n=Hippoboy"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="70" name="Hippoman" race="Tauren" raceId="6" rank="3" url="r=Lightning%27s+Blade&amp;n=Hippoman"/>
    
            <character class="Mage" classId="8" gender="Male" genderId="0" level="21" name="Jamairak" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Jamairak"/>
            <character class="Paladin" classId="2" gender="Female" genderId="1" level="51" name="Jessicalee" race="Blood Elf" raceId="10" rank="3" url="r=Lightning%27s+Blade&amp;n=Jessicalee"/>
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="70" name="Jikeidan" race="Undead" raceId="5" rank="1" url="r=Lightning%27s+Blade&amp;n=Jikeidan"/>
            <character class="Hunter" classId="3" gender="Male" genderId="0" level="70" name="Kakihara" race="Orc" raceId="2" rank="3" url="r=Lightning%27s+Blade&amp;n=Kakihara"/>
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="39" name="Kalph" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Kalph"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="70" name="Marahumal" race="Tauren" raceId="6" rank="3" url="r=Lightning%27s+Blade&amp;n=Marahumal"/>
            <character class="Priest" classId="5" gender="Female" genderId="1" level="70" name="Mirowen" race="Undead" raceId="5" rank="1" url="r=Lightning%27s+Blade&amp;n=Mirowen"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="22" name="Nuajix" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Nuajix"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Reboot" race="Blood Elf" raceId="10" rank="0" url="r=Lightning%27s+Blade&amp;n=Reboot"/>
    
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Rexmaniak" race="Blood Elf" raceId="10" rank="1" url="r=Lightning%27s+Blade&amp;n=Rexmaniak"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="68" name="Roako" race="Tauren" raceId="6" rank="3" url="r=Lightning%27s+Blade&amp;n=Roako"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Sarriz" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Sarriz"/>
            <character class="Hunter" classId="3" gender="Male" genderId="0" level="70" name="Sevenups" race="Troll" raceId="8" rank="1" url="r=Lightning%27s+Blade&amp;n=Sevenups"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Shabobble" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Shabobble"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="70" name="Spearhead" race="Undead" raceId="5" rank="2" url="r=Lightning%27s+Blade&amp;n=Spearhead"/>
            <character class="Rogue" classId="4" gender="Male" genderId="0" level="70" name="Spiritkiller" race="Troll" raceId="8" rank="3" url="r=Lightning%27s+Blade&amp;n=Spiritkiller"/>
            <character class="Warlock" classId="9" gender="Male" genderId="0" level="70" name="Stupify" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Stupify"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="70" name="Sudantu" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Sudantu"/>
    
            <character class="Hunter" classId="3" gender="Male" genderId="0" level="70" name="Trappa" race="Blood Elf" raceId="10" rank="3" url="r=Lightning%27s+Blade&amp;n=Trappa"/>
            <character class="Priest" classId="5" gender="Male" genderId="0" level="70" name="Trie" race="Undead" raceId="5" rank="3" url="r=Lightning%27s+Blade&amp;n=Trie"/>
            <character class="Shaman" classId="7" gender="Male" genderId="0" level="70" name="Twopac" race="Tauren" raceId="6" rank="4" url="r=Lightning%27s+Blade&amp;n=Twopac"/>
            <character class="Mage" classId="8" gender="Male" genderId="0" level="64" name="Uptown" race="Undead" raceId="5" rank="4" url="r=Lightning%27s+Blade&amp;n=Uptown"/>
            <character class="Warrior" classId="1" gender="Male" genderId="0" level="70" name="Warhero" race="Orc" raceId="2" rank="3" url="r=Lightning%27s+Blade&amp;n=Warhero"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Warugi" race="Tauren" raceId="6" rank="3" url="r=Lightning%27s+Blade&amp;n=Warugi"/>
            <character class="Shaman" classId="7" gender="Male" genderId="0" level="70" name="Xereth" race="Troll" raceId="8" rank="2" url="r=Lightning%27s+Blade&amp;n=Xereth"/>
            <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Yaok" race="Tauren" raceId="6" rank="2" url="r=Lightning%27s+Blade&amp;n=Yaok"/>
            <character class="Warlock" classId="9" gender="Female" genderId="1" level="70" name="Zukina" race="Blood Elf" raceId="10" rank="1" url="r=Lightning%27s+Blade&amp;n=Zukina"/>
    
          </members>
        </guild>
      </guildInfo>
    </page>
    
     
  15. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    So like this:

    PHP:
    function CheckRoster(){
        
    $sql "SELECT * FROM miscinfo WHERE title = 'rostertimer'";
        
    $result mysql_query($sql);
        if(
    mysql_query($sql)){
            
    $prev_day mysql_result($result0'info1');
            
    $curr_day date(Ymd);
            if(
    $prev_day<$currday){
                
    UpdateRoster();
            }else{
                
    GetRoster();
            }
        }else{
            return 
    "Error: Could not complete $sql";
        }
    }
     
  16. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    DISCLAIMER: This code is for demonstration purposes only and sends wrong "identification" headers to get the XML content instead the HTML. Do not use it to automatically fetch content of the Blizzard site.

    This server configuration is definatly intentional, be it for compatibility purposes (older browsers can't necessarily do client-side XSL transformations) or to prevent data-mining.

    PHP:
    <?php

    $url 
    'http://armory.worldofwarcraft.com/guild-info.xml?r=Lightning\'s+Blade&n=Paradigm+Shift';

    header('Content-type: text/plain');

    if ((
    $handle curl_init($url)) === false)
    {
        print 
    "[-] curl_init() failed\n";
        exit;
    }

    $headers = array(
      
    'Accept: text/xml,application/xml,application/xhtml+xml',
      
    'Accept-Charset: utf-8,ISO-8859-1'
    );

    curl_setopt($handleCURLOPT_HEADER0);
    curl_setopt($handleCURLOPT_FOLLOWLOCATION1);
    curl_setopt($handleCURLOPT_RETURNTRANSFER1);
    curl_setopt($handleCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070101 Firefox/2.0.0.4');
    curl_setopt($handleCURLOPT_HTTPHEADER$headers);

    if ((
    $content curl_exec($handle)) === false)
    {
        print 
    "[-] curl_exec() failed\n";
        
    curl_close($handle);    
        exit;
    }
    curl_close($handle);    


    if ((
    $xml domxml_open_mem($content)) == false)
    {
        print 
    "[-] domxml_open_mem() failed\n";
        exit;
    }

    $elems $xml->get_elements_by_tagname('character');
    if (empty(
    $elems))
    {
        print 
    "[-] No elements available.\n";
        exit;
    }

    print 
    "[+] Output:\n";
    foreach (
    $elems as $elem)
    {
        print 
    'Name:    ' $elem->get_attribute('name') . "\n"
        
    'Level:    ' $elem->get_attribute('level') . "\n"
        
    'Class:    ' $elem->get_attribute('class') . "\n"
        
    'Race:     ' $elem->get_attribute('race') . "\n"
        
    'Gender: ' $elem->get_attribute('gender') . "\n"
        
    'Url:        ' $elem->get_attribute('url') . "\n\n";
    }


    ?>
     
  17. TFlan

    TFlan I could change this in my User CP.

    Ratings:
    +64 / 0 / -0
    Ok i love you because it worked :D

    BUT im scared of what u mean in the disclaimer....
    Meaning, the code is lying to wow.com?
     
  18. enouwee

    enouwee Non ex transverso sed deorsum

    Ratings:
    +235 / 0 / -0
    Yes, it's pretending to be a Firefox browser, as the Blizzard webserver sends back HTML if you don't provide a supported "User-Agent" and/or "Accept" header, matching a (probably hardcoded) list of browsers known to be able to apply XSLT correctly).

    You shouldn't fetch the stats this way. It might work, but it might also get you in trouble. Better check the terms and conditions or ask for permission.
     

Share This Page