Ok guys I am new here and am seeking help on my code I am working on for my website. So I hope this is the right place to post if not sorry. Anyways, I am working on a steamcommunity.com related website using their API. I have everything working openid grabbing info and so on. I can not figure out why the status is not working properly for me. Below is most of the code I use for calling steam and inserting into my database and trying to add an online function. I do not get why it does not work. I do not know if I am not calling it right on the profile page or what. So here is the code before I ramble on.
[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;
}[/php]
This is basically the entire top part of my code that runs the steam data and inserts into my database. Here is what I use to call the online code on my profile page.
[php]echo "
Status? " . $steam->user[‘onlineoffline’] . " "; [/php]
So what did I do wrong and if anyone can help please do so I will try anything lol. I will announce my site once the code is fixed and so on :). This is not another steam/trading website this will be used for any gamer and steam fan!