PHP - Starting A Steam Api Website...
But 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. Similar TutorialsHey 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; } ?> 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 />" ; } started learning php yesterday at w3schools was looking for a great forum to ask questions as i go along. bumped into phpfreaks. looking forward to mastering the art
I can't for the life of me understand how to perform this so I need some professional help here. I have a large array that contains some garbage every Nth and Nth + 1 element that needs to go away. array_filter doesn't work with keys but anyhow, i wouldn't know how to design the function. My keys are numeric, starting from 0. The keys I want to remove are part of this sequence: 8, 9, 18, 19, 28, 29 ... Can someone help me design a generic function to remove these keys? function filter_keys($array, $n, $offset) {} $new_array = filter_keys($array, 10, 8 ); I would maybe have to run this function twice, once for 8 offset and once for 9 offset. I am starting a project that will encompass the following- A forum script that will later be tied into it's own custom content management system. But I have some questions before I get too deep into starting: 1. What is the "most" secure way to code a forum system? 2. Shall I rely on 1 person to code or open it to the public to help too (open source)? 3. Which features of forum scripts do you like and why? 4. How should the plugin system (hooks) be designed? 5. Template system - what is the easiest way to make theming simple? These are just some of the basics that I am pondering at the moment. I know these may sound noobish but I would rather start this project the right way, instead of having it coded wrong etc.....and having to re-do everything down the road. So I started learning how to code php with usercake. I then went to use different things like fileNice for directory listing and I went to make a music lister with music player running mainly (EDM) .mp3's.
I have uploaded a copy of my music.php file and I would love some help on how to develop my site further!
https://github.com/3...aster/music.php
This is the part I need help developing:
<?php function getUploadedFiles($directory){ $folder = opendir($directory); while ($file = readdir($folder)) { if($file !== '.' && $file !== '..') { $filename = $directory.''.$file; $file_array[] = array('filename' => $file); } } return $file_array; } $music = getUploadedFiles('../Music/EDM'); foreach($music as $value) { echo '<div class="well well-sm">'; echo '<li class="list-group-item list-group-item-success"><div class="alert alert-success" role="alert"><a href="../Music/EDM/'.$value['filename'].'"title="Play .$value" class="sm2_button"></a> '.$value['filename'].'</div></li>'; echo '<p><a href="../Music/EDM/'.$value['filename'].'"><button type="button" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-headphones"> </span> Listen</button></a> '; echo '<a href="../Music/EDM/'.$value['filename'].'" download><button type="button" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-cloud-download"></span> Download</button></p></br></a></p>'; echo '<p><a class="btn btn-default" href="#" role="button">View details »</a></p>'; echo '</div>'; } ?>I would love to figure out how to use "echo '<p><a class="btn btn-default" href="#" role="button">View details »</a></p>';" to show time of when song was added, so Time last modified ? Hopefully I can learn how to set individual counters instead of them being the same for all the songs :/ Here is a link to the site with everything running: http://thebatcave.x10.mx/dev/music.php Tell me what you think ? Edited by 321System123, 10 August 2014 - 08:45 PM. Why do I get the following results (specifically the second example)? I thought it would be documented under https://www.php.net/manual/en/language.types.string.php, however, the word "ampersand" doesn't appear. Also, looked at logical operators, but found nothing. Thanks function test(string $string){ printf('%s %s %s 0'.PHP_EOL, gettype($string), $string, $string==0?'==':'!='); } test('123'); test('@123'); test('1@23'); test('123@');Quote
string 123 != 0
This topic's house has been seized by the bank and it now lives in MySQL Help until it can get back on its feet. http://www.phpfreaks.com/forums/index.php?topic=358035.0 Hey guys just thought I'd introduce myself as it's a polite thing to do.
My name is Nick I am currently a front end developer and love learning new technologies so it looks like PHP is my next step.
I hope to learn and give whatever knowledge I can back
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347327.0 Hello Community, good evening! i am having troubles with starting PHP on linux - [running OpenSuse-Linux] Could not open input file: - suse-linux:/usr/perl # php -v PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/extensions/readline.so' - libedit.so.0: cannot open shared object file: No such file or directory in Unknown on line 0 PHP 5.3.4-dev (cli) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies suse-linux:/usr/perl # well what is wrong here...? I am wondering whether there is a way to do a foreach loop for an array, without starting at index[0]. Say, for example, I wanted to start displaying the contents of a 20 item array starting at index 5, what is the best way to do it? I know of this way, but it seems too crude (ie. there has to be a better way): $count = 0; foreach($array as $item) { if ($count > 5) {echo $item;} $count++; } Any other ideas?? good day dear PHPFreaks - hello to everybody. i want to create a link parser. i have choosen to do it with Curl. I have some lines together now. Love to hear your review... Since i am new to programming i love to get some hints from experienced devs. Here some details: well since we have several hundred of resultpages derived from this one: http://www.educa.ch/dyn/79362.asp?action=search Note: i want to itterate over the resultpages - with a loop. http://www.educa.ch/dyn/79376.asp?id=1568 http://www.educa.ch/dyn/79376.asp?id=2149 i take this loop: for($i=1;$i<=$match[1];$i++) { $url = "http://www.example.com/page?page={$i}"; // access new sub-page, extract necessary data } what do you think? What about the Loop over the target-Urls? BTW: you see - there will be some pages empty. Note - the empty pages should be thrown away. I do not want to store "empty" stuff. well this is what i want to. And now i need to have a good parser-script. Note: this is a tree-part-job: 1. fetching the sub-pages 2. parsing them 3. storing the data in a mysql-db Well - the problem - some of the above mentioned pages are empty. so i need to find a solution to leave them aside - unless i do not want to populate my mysql-db with too much infos.. Btw- parsing should be a part that can be done with DomDocument - What do you think? I need to combine the first part with tthe second - can you give me some starting points and hints to get this. The fetching-job should be done with CuRL - and to process the data into a DomDocument-Parser-Job. No Problem he But how to do the DOM-Document-Job ... i have installed FireBug into the FireFox... now i have the Xpaths for the sites: http://www.educa.ch/dyn/79376.asp?id=1187 http://www.educa.ch/dyn/79376.asp?id=2939 http://www.educa.ch/dyn/79376.asp?id=1515 http://www.educa.ch/dyn/79376.asp?id=1469 Altes Schulhaus Ossingen :: /html/body/div[2] Guntibachstrasse 10 :: /html/body/div[4] 8475 Ossingen :: /html/body/div[6] sekretariat.psossingen@bluewin.ch :: /html/body/div[9]/a Tel:052 317 15 45 :: /html/body/div[11] Fax:052 317 04 42 :: /html/body/div[12] but how to appyl in the Simple DomDocument - i want to use this he http://simplehtmldom.sourceforge.net/ look forward to a hint that gives me a starting point Im trying to make a script that draws the track for a game that i in development, Im stuck on something though. For some reason my script is drawing lines from 0,0 to the x,y of the start position to the x,y of the end position. I have no idea why. Here is the script <?php header ("Content-type: image/png"); $im = ImageCreate (700, 400); $background = ImageColorAllocate ($im, 255, 255, 255); $line = ImageColorAllocate ($im, 0, 0, 0); $trackcode = file_get_contents('test.txt'); $type = split("#", $trackcode); $line = split(",", $type[0]); $sline = split(",", $type[1]); for($i=0; $i<count($line); $i++) { $section = split(" ", $line[$i]); for($j=0; $j<count($section); $j+=2) { $startx = base_convert($section[$j],32,10); $starty = base_convert($section[$j+1],32,10); $endx = base_convert($section[$j+2],32,10); $endy = base_convert($section[$j+3],32,10); //echo "startx: $startx | starty: $starty | endx: $endx | endy: $endy <br>"; imageline ($im,$startx,$starty,$endx,$endy,$line); } } ImagePng ($im); ImageDestroy ($im); ?> You can echo the data if you want to see the raw coordinates. You will need to make a file called test.txt and put this in it for it to work Code: [Select] 42 1i 5u a,8e a 8e -a 8e -u 8e -1i 92 -18 92 0 9m a aa 0 au -a au a,8e -1i 9m -26 au -1i aa -18 9m -1i 92 -18,6i a 84 a,b8 -a b8 a cg u d4 k do u do a do -a do -u cg -1i bs -18,do -u d4 -k bs -18,b8 -a bs -k bs 0 cg a d4 0 d4 -k,e2 k e2 -1i em -18,e2 -u em -k em u,fa -u fu -k gi -u fa -1i em -18,fu -k fu k fu u,gi k gi -u,fa -u em -k,6i a 5u a,gs -u gs 0 gs a i4 u jc a jc -u,gs -18 gs -u,gs -18 hg -1i hg 0 gs a,hg 0 i4 a io 0 jc a,io 0 io -1i jc -18 jc -u,jm a ku u li k m6 u m6 a,jm a jm -a ka -k ka 0 ku a li 0 li -k m6 -u m6 a,li -k ka -18 ku -1i m6 -u,mg a no u p0 a p0 -a oc -k no -u,oc -k p0 -u no -1i no -18 no -a,mg a n4 0 no a oc 0 no -a,qi a qi k r6 u r6 0 t2 u t2 a se 0 t2 -a,qi a qi -a,qi -1i qi 0,qi -1i rq -26 t2 -1i t2 -u t2 -a,r6 -18 rq -1i se -18 t2 -1i,se -18 se -k rq -a r6 -k r6 -18,qi -1i r6 -18,tc k u0 u,tc k tc 0 tc -18 u0 -1i u0 u,ua a vi u 10q a 10q -k 10q -1s 106 -26 106 -1i,ua a ua -a ua -u uu -k uu 0 vi a 106 0 106 -k 10q -u,ua -u vi -1i 106 -18 106 -1i,106 -k vi -u uu -k,114 a 12c u 130 k 11o 0 11o -a,114 a 114 -a 114 -u 12c -1i 13k -u 130 -k 130 -a 130 0 13k -a 13k -u,130 -k 12c -u 11o -k 114 -u,11o -k 11o -a,13u k 13u -u 13u -18 14i -1i 14i 0,13u k 14i u 14i 0,17m a 19i 1i 1es 1i 3d2 1i,pa a q8 a,8e a 9m u au a,e2 k em u,gi k fu u,42 1i -1mm 1i,17m a 14s a#9m -1i 9m -a aa 0,9m -a 92 0,bs 0 cg -a cg -u,cg -a d4 0,bs -k cg -u,em -k fa -a fa a fu 0,fa -a fu -k,em 0 fa a,hg 0 i4 -a io 0,hg -k i4 -u i4 -a,i4 -u io -k,ka 0 ku -a li 0,ku -a ku -u,ka -k ku -u,no -1i mg -u mg -a n4 0,mg -u no -a,no -u n4 -k,r6 -18 rq -u rq -a,rq -u se -18,tc -18 tc -1s u0 -1i,uu 0 vi -a vi -u,vi -a 106 0,11o -k 12c -a 12c a,12c -a 130 -k,130 0 12c a,14i -1i 156 -18 156 -k 14i -u# I have no idea why it isnt working properly, any help will be greatly appreciated. I have a form with some dropdownlist that get populated dynamically(depends on what the user chooses) with jquery and an xml file. In the form I have a button that takes the info and populates another form with the values of the ddl. I have coded script which populates the second form with jquery and the name of each input get dynamically added like so: Code: [Select] <input type="text" value="'+model+'" name="Model_'+model+'" id="'+model+'" readonly size="'+model.length+'" /> <input type="text" value="'+model+'" name="Model'+model+'" id="'+model+'" readonly size="'+model.length+'" />> <input type="text" value="'+color+'" name="Color'+color+'" id="'+color+'" readonly size="'+color.length+'" /> <input type="text" value="'+part+'" name="Part'+part+'" id="'+part+'" readonly size="'+part.length+'" /> <input type="text" value="$'+price+'" name="Price'+price+'" id="'+price+'" readonly size="'+price.length+'" /> <input type="text" value="'+qty+'" name="Quantity'+qty+'" id="'+qty+'" readonly size="'+qty.length+'" /> <input type="text" value="'+total+'" name="Total'+total+'" id="'+total+'" readonly size="'+total.length+'" /> What I want to do is grab the name of the element and remove the underscore and everything else form rileft to right so I am left with just the word before the underscore. I tried using substr($key,0,-28) but that wont work since everything after the underscore will have a different length. I was wondering if there is a way i can keep everything before the underscore and remove the underscore and everything after that. Thanks in advance for any input I get. Hey guys I am getting a Headers error that I havent been able to get rid of for the past 3 hours. I would really appreciate some help. <?php mysql_connect("localhost", "", "")or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $tbl_name="test_mysql"; $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Row</strong></td> <td align="center"><strong>Month - Date</strong></td> <td align="center"><strong>Message</strong></td> <td align="center"><strong>Title</strong></td> <td align="center"><strong>Icon</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="month[]" MAXLENGTH="3" size="3" type="text" id="month" value="<?php echo $rows['month']; ?>"> <input style="border: 1px solid #C3C3C3;height: 20px;" name="date[]" MAXLENGTH="2" size="2" type="text" id="date" value="<?php echo $rows['date']; ?>"> </td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="message[]" size="70" type="text" id="message" value="<?php echo $rows['message']; ?>"></td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="title[]" size="70" type="text" id="title" value="<?php echo $rows['title']; ?>"></td> <td align="center"> <select name="test[]" style="display:block; width:200px" class="mydds"> <option value="icon_phone.gif" title="icon/icon_phone.gif">Phone</option> <option value="icon_sales.gif" title="icon/icon_sales.gif">Graph</option> </select> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><br><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> <?php if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $message = $_POST['message']; $title = $_POST['title']; $monthday = $month[$i]."<br>".$date[$i]; $sql1="UPDATE $tbl_name SET monthday='$monthday', month='$month[$i]', date='$date[$i]', message='" . mysql_real_escape_string($message[$i]) . "', title='" . mysql_real_escape_string($title[$i]) . "' WHERE id='$id[$i]'"; $result1 = mysql_query($sql1); } header("location:update2.php"); } ?> Please Hello dear friends, first of all : merry merry Xmas!!! i want to parse with the simple Simple HTML DOM Parser, well i am pretty new to php and to the Simple HTML DOM Parser. My example: http://schulen.bildung-rp.de/gehezu/startseite/einzelanzeige.html?tx_wfqbe_pi1[uid]=60119 I want to collect the data in the block: I have investigated the sourcecode - and found out that the attribute of interest should be this one: class="content"div class="content"><!-- TYPO3SEARCH_begin --> here the code is: - my trails. // inculde the Simple HTML DOM Parser include_once('simple_html_dom.php'); // get the file we want to parse right now,create a DOM $html = file_get_html(''); // simple_html_dom::find() creates a new // simple_html_dom-Objekt, that consists out of // corresponding childelements foreach($html->find('class: content ') as $h3) { // simple_html_dom::get the text in a tag // den Text innerhalb eines Tags if($h3->innertext == 'Text of a H3 Tag') { break; } } // simple_html_dom::next_sibling() gives the // next Element $table = $h3->next_sibling(); but believe me - it gives me not back what is aimed. what have id done wrong...? dbone Hey, I'm trying to open a .php file and read a comment block that is in the beginning of the file. I'm having some trouble in that nothing is being echoed out. Here is the reading file: <?php $fb = fopen("tepl.php", "r"); $data = fread($fb, 8192); fclose($fb); var_dump($data); ?> here is the file (tepl.php) being read: <?php /* Name: Test Plugin 1 URI: http://www.theorangeday.com/plugintest/ Description: This is just a test plugin because I need to test how this thing is going to work overall. Author: Thomas Francis Author URI: http://www.theorangeday.com/ Version: 0.1 */ function test_plugin(){ echo "we loaded the test plug"; } ?> the var_dump returns Code: [Select] string(321) " " What's wrong here? I just installed this new script here http://webhost.pro/domain-check.php it's a basic domain availability tool. I am trying to make a form that can be used on any page forward to this page with the content. The page loads with this in the url webhost.pro/domain-check.php?domain=dwhs.net and will run the page. So I can make a form that just submits to that page and sends the details. I made this page for testing http://webhost.pro/test.html But no go, here is the code: <form id="search" action="/domain-check.php" method="GET"> <input type="text" name="s"> <a onClick="document.getElementById('search').submit()" class="button1">Search</a> <div class="clear"></div> </form> Thanks! |