PHP - Steam Xml Question
Hey guys,
I'm working on a little image thingy. What I want to do, is use a URL such as , Quote http://steamcommunity.com/profiles/76561197968575517/stats/L4D2/?xml=1 Grab data from it, put the into variables and create an image with the data. I read the tutorial on this website and sort of got stuck.. with external XML files, ALSO this doesn't look like your normal XML file. Here is the code I have thus far.. I got stuck at the 'playerstats' part.. <?php $rss = new SimpleXMLElement('http://steamcommunity.com/profiles/76561197968575517/stats/L4D2/?xml=1', null, true); foreach($rss->xpath('playerstats') as $item) { echo <<<EOF <p> {$item->steamID64} <br /> {$item->hoursPlayed} </p> EOF; } ?> Similar TutorialsBut I need help in an issue I have been having for awhile now. Some reason when I try to call for online status it does not work sometimes i can get it to show the default code 1 which means online. But I am trying to get it to say Online and Offline and so on. I do not get what I am doing wrong my website using mysql so not sure if its having trouble reading the database or what. here is the code...
<?php class steam { public $api = STEAM_API; public $returnUrl = URL; public $user = array(); function __construct() { $this->setUserInfo(); } function isLoggedin() { if(isset($_SESSION['steam'])) { return true; } return false; } function showLogoutButton() { echo "<br /><a href=\"logout.php\">Logout</a>"; //logout button } function steamlogin() { require_once(INCLUDES.'/openid.php'); try { // Change 'localhost' to your domain name. $openid = new LightOpenID($this->returnUrl); //dump($openid); if(!$openid->mode) { if(isset($_GET['login'])) { $openid->identity = 'http://steamcommunity.com/openid'; header('Location: ' . $openid->authUrl()); } echo "<a href=\"?login\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_small.png\"></a>"; } elseif($openid->mode == 'cancel') { echo 'User has canceled authentication!'; } else { if($openid->validate()) { $id = $openid->identity; $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/"; preg_match($ptn, $id, $matches); $_SESSION['loginid'] = $matches[1]; //die('Here'); header('Location: index.php'); exit; } else { echo "User is not logged in.\n"; } //die('here we are'); } } catch(ErrorException $e) { echo $e->getMessage(); } } function doLogout() { if(isset($_POST['steamid'])) { unset($_POST['steamid']); } header('Location: index.php'); exit; } function setUserInfo() { global $DB; if($this->isLoggedin()) { // Grab the info from the session $userData = $DB->getUserById($_SESSION['steam']); if(isset($userData['steamid'])) { $this->user = $userData; } else { unset($_SESSION['steam']); die('Could not get user'); } } elseif(isset($_SESSION['loginid'])) { $url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='.$this->api.'&steamids='.$_SESSION['loginid']; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); curl_close($ch); $content = json_decode($content, true); $_SESSION['steam'] = $_SESSION['loginid']; // Set the database values $values = array( 'steamid' => $content['response']['players'][0]['steamid'], 'communityvisibilitystate' => $content['response']['players'][0]['communityvisibilitystate'], 'profilestate' => $content['response']['players'][0]['profilestate'], 'personaname' => $content['response']['players'][0]['personaname'], 'lastlogoff' => isset($content['response']['players'][0]['lastlogoff']) ? $content['response']['players'][0]['lastlogoff'] : '', 'profileurl' => $content['response']['players'][0]['profileurl'], 'avatar' => $content['response']['players'][0]['avatar'], 'avatarmedium' => $content['response']['players'][0]['avatarmedium'], 'avatarfull' => $content['response']['players'][0]['avatarfull'], 'personastate' => $content['response']['players'][0]['personastate'], 'timecreated' => $content['response']['players'][0]['timecreated'], 'onlineoffline' => $this->user['personastate'] == 1 ? 'Online' : 'Offline', 'status' => $this->getOnlineStatus() ); if($values['lastlogoff'] == '') { $values['lastlogoff'] = 'NA'; } else { $values['lastlogoff'] = date("m/d/Y", $values['lastlogoff']); } // Are updating the user info or adding them? $userExists = $DB->getUserById($_SESSION['steam']); if(isset($userExists['steamid'])) { // We have this user, lets update their info $DB->update('users', $values, array('steamid' => $_SESSION['steam'])); } else { // New user, lets insert them $id = $DB->insert('users', $values); } unset($_SESSION['loginid']); $this->setUserInfo(); } } function getOnlineStatus($values) { switch($this->user['onlineoffline']) { case '0': default: $state = 'Offline'; break; case '1': $state = 'Online'; break; case '2': $state = 'Busy'; break; case '3': $state = 'Away'; break; case '4': $state = 'Snooze'; break; case '5': $state = 'Looking to trade'; break; case '6': $state = 'Looking to play'; break; } return $state; } ?>This is basically my entire code that calls the steam api. Here is the echo function I use to try and call it on a profile.php page... echo "<br /><strong>Online:</strong> " . $steam->user['onlineoffline'] . " ";So I would really appreciate it if someone can help me. I been trying to figure out this for the past week and its starting to drive me nuts and loose motivation on my project. Everything else works great minus this one issue. I have pretty much asked everywhere I can think of and no help. I use a function to call my database hint the global $DB; in my functions just to give you anymore information I can. $steam variable I believe is coming from my class at the very top of my code that is were $steam comes from. Thanks Edited by soslidesigns, 12 August 2014 - 01:50 PM. Hey guys, I'm fairly new to PHP but i know the basics. I've been working with the Steam XML feeds for various reasons and i'm trying to create a list of friends that show whether they are online/offline, show their profile pic... etc... To get a persons friends list (using me as an example) is: http://steamcommunity.com/profiles/76561197970734089/friends?xml=1 But to get to get more information from the friends you take the steamID from the above XML and take information from their main profile XML feed, i have to do this because the normal profile XML (again as me as an example): http://steamcommunity.com/profiles/76561197970734089?xml=1 , only displays 6 friends details at a time. I hope you under stand but please see my PHP below, the problem i'm having is that it takes forever to run the loop and certain mobile browsers just wont display the page (timeout). I didn't know whether you guys being the phpfreaks would know of a faster memory efficient way of doing this? // set the XML file name as a PHP string $friendslist = "http://steamcommunity.com/profiles/76561197970734089/friends/?xml=1" ; // load the XML file $xml = @simplexml_load_file($friendslist) or die ("no file loaded") ; // get the output $steamID = $xml->steamID ; echo "<h1>Main Profile: " . $steamID . "</h1>"; // set the loop foreach ($xml->friends->children() as $friendid) { echo "http://steamcommunity.com/profiles/".$friendid."?xml=1" ; echo "<br />"; $friendget = "http://steamcommunity.com/profiles/".$friendid."?xml=1" ; $friendgot = @simplexml_load_file($friendget) or die ("no file loaded") ; echo $friendgot->steamID ; echo "<br />" ; } when in a form, I wish to build a conditional that if the response to a radio button is a value of 2 (female), it will display an input requesting for users maiden name. If not 2 goes to the next input statement. Here is code I was experimenting with: <html> <body> <form action="" name="test" method='POST'> <input type="radio" id="sex" value=1 checked><label>Male</label> <input type="radio" id="sex" value=2><label>Femaleale</label> <?php $result = "value"; if ($result == 2) echo "<input type='int' id='gradYear' size='3' required>"; else echo "Not a female!" ?> <input type="submit" value="GO"> </form> </body> </html> The code passes debug, however, Not a Female is displayed. My question is - Can I do this and if so, what value do I test against id='sex' or value. I tried each one but gave the same results. I realize that $_POST[sex] would be used after the submit button is clicked. But this has me stumped. Thanks for the assis in advance. In php, which function is best used to act something like the sql "LIKE" command? and how would that function be used like? I'm creating a re classified ad site and I've hit a brick wall. I'm trying to create a 'listing' which will contain info and pictures of the property that's for sale, but I'm unsure on how to do it. Would I have to create different db tables to have the albums, images and listing together? Or would can I just do it all in one table? I appreciate your help. Just get started with OO in PHP. If I create an object while on one page and then call another page, can I still access that first object, or is it destroyed when the second page is called? For example, if I have on page1.php: Code: [Select] $obj = new $MyObject(); and then call page2.php, is it possible to still access $obj while on that page? Hi, I am looking into a way of adding addons to a class I made.. I thought something like this would work, but not sure how to implement it: Code: [Select] <?php class foo { function foobar($text) { $text = $text . 'b'; return $text; } } class bar extends foo { function foobar($text) { $text = $text . 'c'; return $text; } } $var = new bar(); $var->foobar('a'); // this would then return abc ?> Now i want to be able to call up foo, and it calls the foobar of foo, and the foobar of bar. is that possible? hosh I'm considering getting a VPS, but I'm not entirely sure what this would be able the handle. The specs doesn't look that good to me, but my friend swears it will handle running apache/php/mysql handling large websites and databases without a problem. I want to run multiple databases that just store statistics and I'm a bit worried about the RAM and the company doesn't even mention a cpu. Here's the specs: 256MB RAM 300GB HDD 10Mbps unmetered 1 IP Address My friend runs two counter-strike: source servers off his VPS (same stats).. so I'm actually considering this, but it just seems like it's not powerful enough. Oh.. forgot the most important part.. it's only $9. Looking at a forum like PHPbb or similar. Wondering if anyone can tell me how the system (or scripts) manages to pull all the user information when viewing a thread without a massive amount of database calls? For example, lets say 1 thread has 10 different users associated to it. When you view the thread, on the left you see the username, their avatar, when the membership was created, maybe even the users level or amount of interaction. So, for each thread view (or page view) does the program do a SQL Select back to the user database for each user's information or is the users information being pulled from cache somewhere? Any insight into the logistics is greatly appreciated! I am trying something simple, creating some horses and making them race using OOP, creating them is easy, how can i find out which one "won" based on the highest total. Here is what i got so far Code: [Select] <?php class Horse { public $strength; public $speed; public $agility; public function create($name,$age,$odds){ $this->name=$name; $this->odds=$odds; $this->strength=(rand(50,200) * $this->odds - $this->age); $this->speed=(rand(100,400) * $this->odds - $this->age); $this->agility=(rand(150,250) * $this->odds - $this->age); $all=array(0=>"$this->strength",1=>"$this->speed",2=>"$this->agility"); echo "<b>$this->name</b> has a strength of <b>$this->strength</b>, a speed of <b>$this->speed</b> and agility at <b>$this->agility</b>. --- <b>".array_sum($all)."</b><br>"; } } $mix=rand(2,6); $a=new Horse; $a->create("Dave", 2, $mix); $a->create("Dude", 3, $mix); $a->create("Evan", 3, $mix); $a->create("Jill", 15, $mix); $a->create("Flex", 10, $mix); ?> I cant figure out a way to find out who had the highest total, i would love to know what i am doing wrong. I have been away from PHP for a long time and I was looking over my old scripts. I did PHP OOP at one time and I used a paticular method to connect all my methods up and load them. I have been looking at other peoples code and when I look at my code it does not even feel like OOP, I want to know how to you link all the methods (or is it called functions?) in a class up and return them? I use to do this: Code: [Select] <?php class quickFUNC { function note_pad() { // code for notepad } function quickAdminFunc() { // code for admin func $this->note_pad(); } } $quickFUNC = new quickFUNC; if(isset($_GET['id'])) { $act = $_GET['id']; } else { $act = NULL; } switch ($act) { case 1: //some random code to launch case 1 break; default: $quickFUNC ->quickAdminFunc(); ?> This was my code back in the days, as you can see the notepad was called in the admin function then made the admin function default in the case switch. I looked at all my script and the all are layed out like this :S.. Can I get some help please, thank you. hello all, i am having a for each problem. im trying to get two post fields using the foreach function. here is what i have in my form.php: Code: [Select] <?php foreach($_POST['staff'] as $value) { echo "$value - <br />"; } ?> the name of the the fields coming in are Code: [Select] name='staff[]' and the second one is name='descr[]' fields += 1; hi php people, I am wondering will if the code below will work when I call $C->getafoo() will I get foo; I keep getting an error at this point return $this->A->a(); saying the method is not there Code: [Select] class A{ public function a(){ return "foo"; } } class B { public $A; function __construct($A) { $this->A = $A; } public function geta(){ return $this->A->a(); } } class C extends B{ public function getafoo(){ return geta(); } } $C = new C(new A()); echo $C->getafoo(); Code: [Select] <?php if ($News_1_Status=="Y") echo <div class="newstitle" align="left"><?php echo $News_1_Date;?> <a href="<?php echo $News_1_URL;?>"><?php echo $News_1_Name;?></a></div><br>; else echo "Have a nice day!"; ?> how do i get the above script working any clue? Major breakthrough. utf8_encode() allows me to view utf-8 characters in the browser. Therefore, my source data file must be ISO-8859-1 encoded text, right? Am I understanding this correctly?
<?php //mb_internal_encoding("UTF-8"); header('Content-type: text/html; charset=utf-8'); $file = fopen('some_csv_file_created_by_excel.csv', "r"); ob_start(); while (($spec = fgetcsv($file, 100000, ",")) !== FALSE){ echo($spec[0].' '.utf8_encode($spec[0]).'<br>'); } $string=ob_get_clean(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>utf</title> </head> <body> <p><?php echo($string);?></p> </body> </html> Edited by NotionCommotion, 11 January 2015 - 08:22 PM. Code: [Select] /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ @$dom->loadHTML($file); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom->getElementsByTagName('table'); /*** get all rows from the table ***/ $rows = $tables->item(0)->getElementsByTagName('tr'); /*** loop over the table rows ***/ foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('a'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; } Hi, Is there a way to start to echo from 43? thanks. Hello, i am currently working on a project and i have been on google and nothing has helped i am trying to detect characters in the URL so for example XSS if someone typed in the URL:
home.php?=<script>document.cookie();</script> OR home.php?=<?php echo file_get_contents("document.txt", "a");How would i be able to make a kind of firewall to detect this? and if it does then redirect to another page. Thanks. Hello, I have a 'strange' situtation. I have this string "Who Am I" that will be used as an header (site for a client) but the design shows that the word "Who" and the words "Am I" are in 2 different colors, in HTML this is a quick fix, but in PHP? What I was thinking was explode the string and fetch the first element put it in a var en then concat the 2 others. But what if the title is more then 3 elements after exploding? It needs to be more dynamic, but I don't know how to do it. Does anyone have an idea? U guys know in forums how at the top or bottom there links to the "1 2 3 4 5 next" and stuff? and how it loads a database? how would i do that exactly? or explain to me what it could be called. cause me i have no idea :/ I am trying to make it so that it will load if the site if the site is online(EG. $siteonline = 1), and so on. I can't seem to think of how I could do this so it will work from the very top of the page's html, to the very bottom. Like the following code is meant to list all of the stuff in that database. <?php $list_q = mysql_query("SELECT * FROM settings") or die (mysql_error()); while($list_f = mysql_fetch_assoc($list_q)) { } ?> I have my page laid out like this.. <?php include "includes/connect.php"; include "includes/config.php"; ?> <?php $list_q = mysql_query("SELECT * FROM settings") or die (mysql_error()); while($list_f = mysql_fetch_assoc($list_q)) { ?> Html content etc.. <?php } include 'includes/footer.php'; ?> But if I do it that way, It only displays what is in footer.php. |