Skip to content

Instantly share code, notes, and snippets.

@jburns131
Created October 16, 2013 20:43
Show Gist options
  • Save jburns131/7014509 to your computer and use it in GitHub Desktop.
Save jburns131/7014509 to your computer and use it in GitHub Desktop.
<?php
class CurrentUser
{
public $sessionId;
private $id;
private $loggedIn = false;
private $displayName;
private $sessionPersistent;
public function __construct()
{
$cookieName = str_replace('.', '_', $_SERVER['SERVER_NAME']) . '_acms';
if (isset($_COOKIE[$cookieName])) {
$sql = new Db;
$sql->dbSelect('users', 'id, display_name', 'acms_id = :acms_id', ['acms_id' => urldecode($_COOKIE[$cookieName])]);
$result = $sql->dbFetch('one');
if ($result !== false) {
// Setup Current User Info
$this->id = $result['id'];
$this->displayName = $result['display_name'];
$this->loggedIn = true;
$sql->dbUpdate('users',
[
'last_login_time' => (string) date("Y-m-d H:i:s", time()),
'last_ip' => $_SERVER['REMOTE_ADDR'],
], 'id = :id', ['id' => $result['id']]
);
}
} else {
return false;
}
}
public function getId()
{
if (!empty($this->id)) {
return $this->id;
}
return 0;
}
public function isLoggedIn()
{
return $this->loggedIn;
}
public function displayName()
{
return $this->displayName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment