|
|
#1 | |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
*** LOOK AT THE BOTTOM FOR THE SOLUTION - POST 12 ***
Can anyonw help me get it working? I put in my steam ID and now it dont work... pretty sure I used this script before, does anyone know whats wrong? (trying to add an online message on my website that tells my friends if im offline/online) Quote:
Last edited by Mezo: 04-30-2012 at 03:57 PM. |
|
|
|
|
|
|
#2 | |
![]() Join Date: Jan 2012
Reputation: 188
Posts: 241
|
What error do you mean? Returning:
Quote:
I optimized your script: Code:
// Function returns Steam status (default timeout: 5 seconds)
function get_steam_status($steamID64, $timeout = 5) {
$context = stream_context_create(array('http' => array('timeout' => $timeout)));
$file = @file_get_contents('http://steamcommunity.com/profiles/' . $steamID64 . '/?xml=1', false, $context);
$xml = simplexml_load_string($file);
if (isset($xml->onlineState)) {
$online_state = (string)$xml->onlineState;
$state_message = ($online_state == 'offline' ? 'Offline' : (string)$xml->stateMessage);
} else {
// Error loading profile
$online_state = 'offline';
$state_message = 'Offline';
}
$state_css = array('online' => 'on', 'in-game' => 'ing', 'offline' => 'off');
return 'Steam status: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a></span>';
}
// ID = Last part of your profile url (http://steamcommunity.com/profiles/76561197966744834)
echo get_steam_status('76561197966744834');
(You could also use cURL to get the profile or regex to read the state, bit I used the same functions as in your original code...)
Last edited by slazer2k5: 04-24-2012 at 12:37 AM. |
|
|
|
|
|
|
#3 | |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
Quote:
![]() (Yea I'm bad on php hehe) + rep! |
|
|
|
|
|
|
#4 |
![]() Join Date: Jan 2012
Reputation: 188
Posts: 241
|
Hm, it's one code, only the start- and ending-tag was missing:
Code:
<?php
// Function returns Steam status (default timeout: 5 seconds)
function get_steam_status($steamID64, $timeout = 5) {
$context = stream_context_create(array('http' => array('timeout' => $timeout)));
$file = @file_get_contents('http://steamcommunity.com/profiles/' . $steamID64 . '/?xml=1', false, $context);
$xml = simplexml_load_string($file);
if (isset($xml->onlineState)) {
$online_state = (string)$xml->onlineState;
$state_message = ($online_state == 'offline' ? 'Offline' : (string)$xml->stateMessage);
} else {
// Error loading profile
$online_state = 'offline';
$state_message = 'Offline';
}
$state_css = array('online' => 'on', 'in-game' => 'ing', 'offline' => 'off');
return 'Steam status: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a></span>';
}
// ID = Last part of your profile url (http://steamcommunity.com/profiles/76561197966744834)
echo get_steam_status('76561197966744834');
?>
|
|
|
|
|
|
#5 |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
Thanks!
Yea, it was so short and looked so different from the one I posted I thought it was not the complete code hehe. but I took the code, put it in a .txt then renamed it to test.php and uploaded it to test it and it shows me as offline when im online... Any ideas? http://splitzgames.com/terraria/test.php |
|
|
|
|
|
#6 |
![]() Join Date: Sep 2008
Reputation: 4237
Posts: 13,590
|
I don't know what you changed on your site, but the exact code slazer2k5 posted is working for me.
Code:
[netshroud@sunfire:~] $ php test.php Steam status: <span class="steam_on"><a href="http://steamcommunity.com/profiles/76561197966744834/" target="_blank">Online</a></span>[netshroud@sunfire:~] $ |
|
|
|
|
|
#7 |
![]() Join Date: Jan 2012
Reputation: 188
Posts: 241
|
|
|
|
|
|
|
#8 |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
Mangr0v3
I didn't change anything in the code, as I said i posted the code just as it was in a txt document i renamed to test.php and uploaded. with no extra in it or anything left out. slazer2k5 I took the new short code, pasted it into an blank .php file, then uploaded and nothing shows on it.. Last edited by Mezo: 04-26-2012 at 03:34 AM. |
|
|
|
|
|
#9 | |
![]() Join Date: Jan 2012
Reputation: 188
Posts: 241
|
Quote:
Try this code, it's using another method to download the profile data, perhaps the one used before is deactivated on your server: Code:
<?php
// Function returns Steam status (default timeout: 5 seconds)
function get_steam_status($steamID64, $timeout = 5) {
$ch = curl_init();
$curl_options = array(
CURLOPT_URL => 'http://steamcommunity.com/profiles/' . $steamID64 . '/?xml=1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => $timeout
);
curl_setopt_array($ch, $curl_options);
$data = curl_exec($ch);
$xml = @simplexml_load_string($data);
if (isset($xml->onlineState)) {
$online_state = (string)$xml->onlineState;
$state_message = ($online_state == 'offline' ? 'Offline' : (string)$xml->stateMessage);
} else {
// Error loading profile
$online_state = 'offline';
$state_message = 'Offline';
}
$state_css = array('online' => 'on', 'in-game' => 'ing', 'offline' => 'off');
return 'Steam status: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a></span>';
}
// ID = Last part of your profile url (http://steamcommunity.com/profiles/76561197966744834)
echo get_steam_status('76561197966744834');
?>
|
|
|
|
|
|
|
#10 |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
I noticed it says:
"I am: In-Game Terraria on Steam" It makes 2 lines when you launched a game... how to make it into one single line of text. And yes, I changed the line to Code:
return 'I am: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a> on Steam</span>'; And once again thanks so much for your effort on helping me ![]() Appreciate it much!
Last edited by Mezo: 04-26-2012 at 03:33 AM. |
|
|
|
|
|
#11 |
![]() Join Date: Jul 2010
Reputation: 266
Posts: 483
|
Change (string)$xml->stateMessage to str_replace('<br />', ' ', $xml->stateMessage) that'll remove line break for you
Last edited by s333ftricky: 04-26-2012 at 01:18 AM. |
|
|
|
|
|
#12 |
![]() Join Date: Feb 2008
Reputation: 25
Posts: 352
|
Thanks mr s333ftricky and everyone who helped me
![]() The script is now open on http://splitzgames.com/terraria/ And here is the final code on "Display steam status on webpage" for google purpose. You can try 2 codes! CODE 1 - (Used on my website). Code:
<?php
// Function returns Steam status (default timeout: 5 seconds)
function get_steam_status($steamID64, $timeout = 5) {
$ch = curl_init();
$curl_options = array(
CURLOPT_URL => 'http://steamcommunity.com/profiles/' . $steamID64 . '/?xml=1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => $timeout
);
curl_setopt_array($ch, $curl_options);
$data = curl_exec($ch);
$xml = @simplexml_load_string($data);
if (isset($xml->onlineState)) {
$online_state = (string)$xml->onlineState;
$state_message = ($online_state == 'offline' ? 'Offline' : str_replace('<br />', ' ', $xml->stateMessage));
} else {
// Error loading profile
$online_state = 'offline';
$state_message = 'Offline';
}
$state_css = array('online' => 'on', 'in-game' => 'ing', 'offline' => 'off');
return 'I am: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a> on Steam</span>';
}
// ID = Last part of your profile url (http://steamcommunity.com/profiles/76561197966744834)
echo get_steam_status('76561197966744834');
?>
CODE 2 Code:
<?php
// Function returns Steam status (default timeout: 5 seconds)
function get_steam_status($steamID64, $timeout = 5) {
$context = stream_context_create(array('http' => array('timeout' => $timeout)));
$file = @file_get_contents('http://steamcommunity.com/profiles/' . $steamID64 . '/?xml=1', false, $context);
$xml = simplexml_load_string($file);
if (isset($xml->onlineState)) {
$online_state = (string)$xml->onlineState;
$state_message = ($online_state == 'offline' ? 'Offline' : (string)$xml->stateMessage);
} else {
// Error loading profile
$online_state = 'offline';
$state_message = 'Offline';
}
$state_css = array('online' => 'on', 'in-game' => 'ing', 'offline' => 'off');
return 'Steam status: <span class="steam_' . $state_css[$online_state] . '"><a href="http://steamcommunity.com/profiles/' . $steamID64 . '/" target="_blank">' . $state_message . '</a></span>';
}
// ID = Last part of your profile url (http://steamcommunity.com/profiles/76561197966744834)
echo get_steam_status('76561197966744834');
?>
Last edited by Mezo: 04-30-2012 at 03:59 PM. |
|
|
|
|
|
#13 | |
![]() Join Date: Nov 2011
Reputation: 0
Posts: 14
|
response from steam about Steam Community XML
Quote:
|
|
|
|
|
|
|
#14 |
![]() Join Date: Jan 2012
Reputation: 188
Posts: 241
|
Perhaps this should be an answer for this thread :P
|
|
|
|
|
|
#15 |
|
Banned
Join Date: Apr 2012
Reputation: 209
Posts: 1,167
|
^ Mine only fetch a new xml every 5 mins tops, the rest of the time it'll use a cache from the server it runs on. So it matters not to me. 60/5x24 = 288, so that leaves me with 99.712 fetches before hitting the limit lol. Also if a 503 error comes up, it'll retry to get a new xml until the xml is no longer 0 bytes on the server.
It's all about programming properly and thinking ahead. Last edited by Mr SmokesAlot: 05-01-2012 at 10:47 AM. |
|
|
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|