1 | <?php |
---|
2 | /* |
---|
3 | * Modified by Anne Sapyx [I.NET] 17-07-2008 |
---|
4 | */ |
---|
5 | |
---|
6 | class Api |
---|
7 | { |
---|
8 | function Api() |
---|
9 | { |
---|
10 | $this->apiroot_ = "api.eve-online.com"; |
---|
11 | } |
---|
12 | |
---|
13 | function getCharId($name) |
---|
14 | { |
---|
15 | return getdata($this->apiroot_,"/eve/CharacterID.xml.aspx",$name); |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | function getdata($apiroot, $target, $name) |
---|
20 | { |
---|
21 | $fp = fsockopen($apiroot, 80); |
---|
22 | |
---|
23 | if (!$fp) |
---|
24 | { |
---|
25 | echo "Could not connect to API URL<br>"; |
---|
26 | } else { |
---|
27 | // make the Namelist |
---|
28 | $list="names=".str_replace(' ', '%20', $name); |
---|
29 | |
---|
30 | // request the xml |
---|
31 | fputs ($fp, "POST $target HTTP/1.0\r\n"); |
---|
32 | fputs ($fp, "Host: $apiroot\r\n"); |
---|
33 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
34 | fputs ($fp, "User-Agent: EDNKillboard\r\n"); |
---|
35 | fputs ($fp, "Content-Length: " . strlen($list) . "\r\n"); |
---|
36 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
37 | fputs ($fp, "$list\r\n"); |
---|
38 | |
---|
39 | // retrieve contents |
---|
40 | $contents = ""; |
---|
41 | while (!feof($fp)) |
---|
42 | $contents .= fgets($fp); |
---|
43 | |
---|
44 | // close connection |
---|
45 | fclose($fp); |
---|
46 | |
---|
47 | // Retrieve Char ID |
---|
48 | $start = strpos($contents, "characterID=\""); |
---|
49 | if ($start !== FALSE) |
---|
50 | $contents = substr($contents, $start + strlen("characterID=\"")); |
---|
51 | |
---|
52 | $start = strpos($contents, "\" xmlns:row=\"characterID\" />"); |
---|
53 | if ($start !== FALSE) |
---|
54 | $contents = substr($contents, 0, (strlen(substr($contents, $start)))*(-1)); |
---|
55 | } |
---|
56 | return (int)$contents; |
---|
57 | } |
---|
58 | ?> |
---|