*Update*
Since my old tutorial files are lost I made some new ones.
You can check them out here:
php_ajax_armory_tutorial - rothui - Google Code
Three files are needed.
- A basic PHP file that does the structure and includes links that will call your AJAX function
guild_data.php - rothui - Google Code
- Some JavaScript functions to retrieve stuff
armory.js - rothui - Google Code
- Another PHP file that is called by the AJAX function and retrieves the information for you
get_char_data_xml.php - rothui - Google Code
As some posts on page 3 already have mentioned we are now using a class that contains the retrieved information.
If your webserver does not support CURL you can try this function to get the XML string instead. If it does support CURL you should make use of it.
function get_xml_data_from_url($url,$lang)
{
$url_array = parse_url($url);
$fp = fsockopen($url_array['host'], 80, $errno, $errstr, 5);
$send = "GET " . $url_array[path] . "?" . $url_array[query] ." HTTP/1.0\r\n";
$send .= "Host: " . $url_array[host] . " \r\n";
$send .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
$send .= "Accept-Language: " . $lang . "\r\n";
$send .= "Connection: Close\r\n\r\n";
fwrite($fp, $send);
while ($fp && !feof($fp))
{
$headerbuffer = fgets($fp, 1024);
if (urlencode($headerbuffer) == "%0D%0A")
{
break;
}
}
$xml_data = '';
while (!feof($fp))
{
$xml_data .= fgets($fp, 1024);
}
fclose($fp);
return $xml_data;
}
Remember: If you do not support the Request with a browser information the response will be HTML and not XML always. So if you want an XML response add some kind of user agent information. But sometimes HTML is wanted, tooltips for example.
Oh btw...Don't spam the armory server with requests or you will find yourself banned temporarily shortly after.