0

Im trying to load the following XML url and some data within into my database.

https://zkillboard.com/api/kills/corporationID/98115872/pastSeconds/7200/xml/

i have the following code:

<?php 
// INCLUDE DB CONNECTION FILE
include("includes/connect.php");
// CHANGE THE VALUES HERE
include("includes/config.php");
$url = "https://zkillboard.com/api/kills/corporationID/98115872/pastSeconds/7200/xml/";
// RUN XML DATA READY FOR INSERT
$xml = simplexml_load_file($url);
// Loop Through Names
$insertValues = array();
$modifiedTS = date('Y-m-d h:i:s');
foreach ($xml->result->rowset[0] as $value)
{
        //Prepare the values
        $killID = $value['killID'];
        $solarSystemID = mysql_real_escape_string($value['solarSystemID']);
        $killTime = $value['killTime'];
        $moonID = $value['moonID'];
        $allianceName = $value['allianceName'];
        $corporationName = $value['corporationName'];
        $damageTaken = $value['damageTaken'];
//Create and run ONE INSERT statement (with UPDATE clause)
    $insert = "INSERT INTO `killLog` (killID,solarSystemID,killTime,moonID,allianceName,corporationName,damageTaken,last_modified) VALUES('$killID','$solarSystemID','$killTime','$moonID','$allianceName','$corporationName','$damageTaken','$modifiedTS') ON DUPLICATE KEY UPDATE 
last_modified = '$modifiedTS'";
mysql_query($insert) or die(mysql_error());
};
?>

but i get the following errors when accessing the PHP file.

Warning: simplexml_load_file(https://zkillboard.com/api/kills/corporationID/98115872/pastSeconds/7200/xml/) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 406 Non-acceptable encoding. Please use gzip or deflate in /homepages/*****/*****/htdocs/*****/tool/admin/api_killLog.php on line 14

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "https://zkillboard.com/api/kills/corporationID/98115872/pastSeconds/7200/xml/" in /homepages/*****/*****/htdocs/*****/tool/admin/api_killLog.php on line 14

Warning: Invalid argument supplied for foreach() in /*****/*****/htdoc/*****/tool/admin/api_killLog.php on line 19

what am i doing wrong??

2
  • possible duplicate of Load gzipped XML file with simplexml_load_file() Commented Mar 23, 2015 at 0:30
  • i believe this link might help with my error, do i need to pass gzip in headers or something? how can i do this? Commented Mar 24, 2015 at 0:21

1 Answer 1

1

Its a simple case of setting deflate in the curl header.

My code is

function get_url_content( $url ) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'xxxxxx Scraper Tool 1.1');
    curl_setopt($ch, CURLOPT_ENCODING, 'deflate');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);

    $output = curl_exec($ch);

    if (curl_errno($ch)) {
        die('Curl error: ' . curl_error($ch));
    }

    if (function_exists('curl_getopt')) {
        $http_code = curl_getopt($ch, CURLINFO_HTTP_CODE);
        if ($http_code != 200) {
            die('Error response from their server - error code: ' . $http_code);
        }
    }

    curl_close($ch);

    return $output;
}

If you need a hand with your coding send me a evemail in game, DaveTheGreat

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.