fronix
Member
Hello,
I've searched the forums here and found some really helpful posts but they missing some stuff that I need explained.
This is my current login function but I'm not sure of how it works. Earlier today this worked but now I have done something and now it wont work and can't figure out the problem.
I keep getting this error
And this is what I include on the index.php page
And this is my functions file
I've searched the forums here and found some really helpful posts but they missing some stuff that I need explained.
This is my current login function but I'm not sure of how it works. Earlier today this worked but now I have done something and now it wont work and can't figure out the problem.
PHP:
function login($data)
{
$loginModel = XenForo_Model::create('XenForo_Model_Login');
$userModel = XenForo_Model::create('XenForo_Model_User');
$error = "";
$userid = $userModel->validateAuthentication($data['login'], $data['password'], $error);
if (!$userid)
{
$loginModel->logLoginAttempt($data['login']);
return $error;
}
$loginModel->clearLoginAttempts($data['login']);
if ($data['remember'])
{
$userModel->setUserRememberCookie($userid);
}
XenForo_Model_Ip::log($userid, 'user', $userid, 'login');
$userModel->deleteSessionActivity(0, $this->request->getClientIp(false));
$session = XenForo_Application::get('session');
$session->changeUserId($userid);
XenForo_Visitor::setup($userid);
return;
}
I keep getting this error
Code:
An exception occurred: No entry is registered for key 'session' in /storage/content/82/10398/public_html/forum/library/XenForo/Application.php on line 815
XenForo_Application::get() in /storage/content/82/10398/public_html/includes/functions.php at line 49
Session->login() in /storage/content/82/10398/public_html/index.php at line 16
And this is what I include on the index.php page
PHP:
require_once('forum/library/XenForo/Autoloader.php');
$startTime = microtime(true);
XenForo_Autoloader::getInstance()->setupAutoloader('forum/library');
XenForo_Application::initialize('forum/library', XF_ROOT);
XenForo_Application::set('page_start_time', $startTime);
XenForo_Application::disablePhpErrorHandler();
XenForo_Application::setDebugMode(true);
include("includes/functions.php");
$isOnline = $session->isOnline();
$avatarUrl = XenForo_Template_Helper_Core::callHelper('avatar', array($isOnline, 'm', null, false));
restore_error_handler();
restore_exception_handler();
And this is my functions file
PHP:
<?php
class Session {
#Xenforo if logged in function
function isOnline(){
$session = new XenForo_Session();
if (!$session->sessionExists())
{//when user info and sessions are needed
XenForo_Session::startPublicSession();
$visitor = XenForo_Visitor::getInstance();
if ($visitor->getUserId())
{
$userModel = XenForo_Model::create('XenForo_Model_User');
$userinfo = $userModel->getFullUserById($visitor->getUserId());
return $userinfo;
}
}else{
return false;
}
}
function login($data)
{
$loginModel = XenForo_Model::create('XenForo_Model_Login');
$userModel = XenForo_Model::create('XenForo_Model_User');
$error = "";
$userid = $userModel->validateAuthentication($data['login'], $data['password'], $error);
if (!$userid)
{
$loginModel->logLoginAttempt($data['login']);
return $error;
}
$loginModel->clearLoginAttempts($data['login']);
if ($data['remember'])
{
$userModel->setUserRememberCookie($userid);
}
XenForo_Model_Ip::log($userid, 'user', $userid, 'login');
$userModel->deleteSessionActivity(0, $this->request->getClientIp(false));
$session = XenForo_Application::get('session');
$session->changeUserId($userid);
XenForo_Visitor::setup($userid);
return;
}
function logout()
{
// remove an admin session if we're logged in as the same person
if (XenForo_Visitor::getInstance()->get('is_admin'))
{
$adminSession = new XenForo_Session(array('admin' => true));
$adminSession->start();
if ($adminSession->get('user_id') == XenForo_Visitor::getUserId())
{
$adminSession->delete();
}
}
XenForo_Model::create('XenForo_Model_Session')->processLastActivityUpdateForLogOut(XenForo_Visitor::getUserId());
XenForo_Application::get('session')->delete();
XenForo_Helper_Cookie::deleteAllCookies(
array('session'),
array('user' => array('httpOnly' => false))
);
XenForo_Visitor::setup(0);
return true;
}
}
$session = new Session;
?>