4
function retrieveProfile() 
{
    $url = "http://steamcommunity.com/profiles/{$this->steamID64}/?xml=1";
    $profileData = simplexml_load_string($url);

    if(!empty($profileData->error)) { return NULL; }

    $this->friendlyName  = (string) $profileData->steamID;  
}

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found

Warning: simplexml_load_string() [function.simplexml-load-string]: http://steamcommunity.com/profiles/76561197991676121/?xml=1

Warning: simplexml_load_string() [function.simplexml-load-string]: ^

This is the XML file:

http://steamcommunity.com/profiles/76561197991676121/?xml=1

I got no ideea why it does not work and yes it have <?xml version="1.0" encoding="UTF-8" standalone="yes"?> header ! Tried $profileData = new SimpleXMLElement(file_get_contents($url)) too but I get the same result.

Why is this happening ? How can I solve it? I am searching for 3 hours and see only answers that won't help me .
Errors : http://img824.imageshack.us/img824/9464/errorszz.png

EDIT1 : simplexml_load_string was one of my mistakes but now I get even more errors with simplexml_load_file - Tells me that the document is empty... (Not true !)

virusbogdan
  • 187
  • 1
  • 3
  • 13

2 Answers2

6

You are loading the URL as your XML source. You should have:

$profileData = simplexml_load_file($url);
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
  • Now I have even more errors ! Document is empty in /home/a3184184/public_html/openid/includes/SteamAPI.class.php on line 20 + the others ! http://img824.imageshack.us/img824/9464/errorszz.png – virusbogdan Aug 21 '12 at 17:21
  • @virusbogdan What's on line 20? I tried parsing `http://steamcommunity.com/profiles/76561197991676121/?xml=1` with your code it works fine. – Tchoupi Aug 21 '12 at 17:30
  • I know it works fine but not for me. On line 20 : $profileData = $profileData = simplexml_load_file($url); – virusbogdan Aug 21 '12 at 17:39
  • Can you print the `$url` before? `echo $url;` and check that the value is what you expect. Can you do a `$data = file_get_contents($url)` and then echo `$data`? Do you get the content of the file? – Tchoupi Aug 21 '12 at 17:43
  • $url is right but $data looks empty ... Interesting . How come it's empty? I did echo "[" . $data . "]"; and returns [] – virusbogdan Aug 21 '12 at 17:48
  • $url is http://steamcommunity.com/profiles/76561197991676121/?xml=1 ... And it's right .. – virusbogdan Aug 21 '12 at 17:50
  • Interesting... what does `var_dump(ini_get('allow_url_fopen'));` say? – Tchoupi Aug 21 '12 at 17:50
  • string(1) "1" - So url fopen is enabled on this free host. – virusbogdan Aug 21 '12 at 17:51
  • @virusbogdan They could block external access some other way. It's hard to guess. You should contact your host support, or maybe you can try cURL if it's available. – Tchoupi Aug 21 '12 at 17:57
  • cURL is not available. And it worked before - restored to that version and it does the same now. – virusbogdan Aug 21 '12 at 17:58
  • Note : When you go on that link it changes to http://steamcommunity.com/id/virusbogdan/?xml=1 I will try with this new link ! Oh wow - now it works - Seems the URL changes on request and return null (obvious) ... Thank you for head up – virusbogdan Aug 21 '12 at 17:59
1

Url was changing from steamcommunity.com/profiles/76561197991676121/?xml=1 to http://steamcommunity.com/id/virusbogdan/?xml=1 . Obviously the first link returns null so there was an error. Problem solved !

virusbogdan
  • 187
  • 1
  • 3
  • 13
  • Not so obvious. `file_get_contents()` is supposed to follow redirects, and it did when I tested it. It could be a PHP issue: https://bugs.php.net/bug.php?id=53018. But... whatever works for you. – Tchoupi Aug 21 '12 at 18:04
  • Obvious for my host* . Now I need to find out how to grab that redirect link... Any ideea? – virusbogdan Aug 21 '12 at 18:05
  • Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" - returns me null link.. – virusbogdan Aug 21 '12 at 18:59
  • If it doesn't work, use `get_headers()` and access the `Location:` header. – Tchoupi Aug 21 '12 at 20:29