Jump to content

Calling user instance from php script


Recommended Posts

Hey all,

I am using the following code in a php script to grab config data and db data, this works perfectly.

require 'ini.inc.php';
define('ADMIN_CP', true);
require 'includes/functions.inc.php';
$GLOBALS['cache'] = Cache::getInstance();
$GLOBALS['db'] = Database::getInstance($glob);
$GLOBALS['config'] = Config::getInstance($glob);
$GLOBALS['config']->merge('config', '', $config_default);

I am having trouble getting user data... when I add:

$GLOBALS['user'] = User::getInstance();

It results in the following error:

[Wed Dec 27 20:19:02.242234 2023] [proxy_fcgi:error] [pid 13504] [client] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function load() on null in /XXX/classes/user.class.php:1135\nStack trace:\n#0 /XXX/classes/user.class.php(143): User->_load()\n#1 /XXX/classes/user.class.php(167): User->__construct()\n#2 /XXX/player.php(19): User::getInstance()\n#3 {main}\n  thrown in /XXX/classes/user.class.php on line 1135', referer: https://domain.com

Is there a way to get data from the current user instance?



Link to comment
Share on other sites

Please show us line 1135 in the file /classes/user.class.php.

I cannot determine what version of CubeCart has user.class.php, line 1135, has a statement that makes a call to load().

The closest statement I can see is a call to $GLOBALS['hooks']->load('class.user.load').

So, generally speaking, CubeCart has a specific sequence of waking up that has very little leeway - where a call to instantiate class 'n+1' will require that class 'n' be instantiated first.

That is to say, instantiating User might require that every class listed ahead of it be instantiated first -- in this case, at least the Hookloader class and Session class, which themselves might require earlier listed classes be instantiated, such as Language and Debug.

Try including controller.index.inc.php -- which might require you to check the necessity for define('ADMIN_CP', true);.

Edited by bsmither
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...