PHP SESSION variable breaks - php

I have a PHP website that runs on AWS and on a local WAMP host. If I use a browser (lets say Chrome) to log into the AWS application and then open a new tab to log into the local application, the SESSION variable breaks on the AWS server. And I literally mean break, the error I get is
PHP Fatal error: Call to undefined method stdClass::refreshState()
The SESSION has a field ("helper") that contains an object. If I print the Session out after the critical error then it still has the "helper" object, but it only has the first 4 fields from the class definition, the rest are gone. The above mentioned error happens because the refreshState method just disappeared along with the rest of the class methods and fields
For reference, this is the first part of the helper class:
class SessionHelper
{
const VIEW_TYPE_LANDING = "landing";
const VIEW_TYPE_USER = "user";
const VIEW_TYPE_ADMIN = "admin";
public $logged_in_user_id;
public $logged_in_org_user_id;
public $login_date;
public $prev_login_date;
public $current_org_id;
...
Printing the instance out after it breaks yields:
The session stays broken in the browser even after restarting the browser. The only way to fix the error is to clear the browsing history on the browser, after which the error is gone. Any ideas what could be causing this? Any information regarding SESSIONS that break in this fashion would be welcome

Related

Jomsocial error - Notice: JFactory::getUser(): The script tried to execute a method or access a property of an incomplete object

Im getting 2 errors. I saw that Jomsocial had the problem with their own site and fixed it but never posted how. Happens when you go to post an update in jomsocial and it locks up. You refresh the page and get
Error
Sorry, User ID not found.
with the following errors. Then you go login and check the profile and the update was posted fine.
Notice: JFactory::getUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxxx/public_html/libraries/joomla/factory.php on line 244
Notice: CUser::CUser(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/xxxxxx/public_html/components/com_community/libraries/user.php on line 52
What version of JomSocial do you use? This issue shouldn't happen

PHP Fatal-Error: Call to a member function append_output()

I use codeigniter in my blog and since a while I get this error
PHP Fatal error: Call to a member function append_output() on a non-object in /var/www/site/blog/system/core/Loader.php on line 862
I don't know what change caused this and why it appears. The site gets rendered and send to browser completely, from views header.php, index.php to footer.php everything is there and after that this error appears. Search with google showed another site, that has this error at the very bottom of their site...
I now supressed the error with error_reporting(0) as the whole site works fine, but that's not a solution I want to stay with.
It happens on all pages, I have one Controler (blog.php) and several methods like index(), article(), archive() in it. The methods do what they are supposed to do, but when CI finished rendering the page, the error appears, with all controler methods.
What can I do to trace where this problem appears?
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Loader.php#L938
If the error is occurring on the value returned from get_instance, here will be your problem. Although you may have to look at the version you are using to get the right line number.
Additionally:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Controller.php#L75
This appears to be the singleton class that function leads to, it is returning self::$instance which is created in the constructor.
To me this means the CI_Controller singleton has not been instantiated at the time that error has occurred.
Hope that helps you debug your problem.
I had the same problem. I'd overwritten the output class ($this->output) in my controller.

PHP Fatal error: Invalid serialization data for DateTime object at session_start()

We have a Wordpress plugin which sometimes experiences a problem where the page is blank and no amount of refresh/reset will work - the only thing that solves it is to close and restart the browser and thereby force a new session.
The error I get in the logs is
PHP Fatal error: Invalid serialization data for DateTime object in /path/to/my/file on line 15
The line refers to my session class. The class is simply a wrapper class for an array of data which is then saved in the normal PHP session. The line number refers to a line in the constructor for the session class in which we run session_start. Specifically:
if (!session_id()) {
session_start(); //This is the line from the error logs
}
We do have a class in our plugin which extends DateTime and we do store such objects in the session, but the error is not the one I would expect if we had called session_start too early - apart from anything else it refers to DateTime, not our class at all. It could of course be something that Wordpress or another plugin has put in the session. It only appears to happen sometimes and loading the same page in a new sesion is then OK.
Running PHP 5.4.21 in a LAMP stack with Wordpress 3.7.1
Any ideas?
There is not much to write as an answer. The problem isn't related to your (or wordpress) code.
It's a bug in php.
And it's affecting debian php package (possibly some others too).

Error notices using Linkedin Plugin in Cakephp

I am trying to put a Linkedin plugin in cakephp, using this tutorial http://excellencetechnologies.co.in/Telephonia/blog/linked-login-integration-in-cakephp/
Everything works fine until I login in linkedin but after that I get directed to a page with just this two errors:
Notice (8): OAuthRequest::from_consumer_and_token(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "OAuthToken" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition [APP\Plugin\Linkedin\Vendor\OAuth\OAuth.php, line 316]
Notice (8): OAuthSignatureMethod_HMAC_SHA1::build_signature() [oauthsignaturemethod-hmac-sha1.build-signature]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "OAuthToken" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition [APP\Plugin\Linkedin\Vendor\OAuth\OAuth.php, line 126]
I can't find what may be causing them anywhere online so I was wondering if anyone here might know what is causing this.
Wherever in the code the plugin is pulling the access token from session like this:
$accessToken = $this->Session->read($this->sessionAccess);
It is pulling the token in the form of __PHP_Incomplete_Class object. To correct this problem you would have to unserialize the $accessToken like this:
$accessToken = $this->Session->read($this->sessionAccess);
$accessToken = unserialize (serialize ($accessToken));
I did it at the three spots in the code to correct it.
Hopefully it will work for you as well.

Problems with a login php script - passing objects through a session

I have an index.php page that creates a new Login class (login class does all the handling of data,creating session, redirecting, etc)
index.php I create a new login class
require_once('login.class.php');
$login = new Login;
Login constructor looks like this
public function __construct(){
// Start session and open a database connection
session_start();
$this->connectToDB();
}
if the user logs in successfully, I redirect him to securePage.php.
if I do the following on the securePage.php
$test = $_SESSION ['usrData'];
var_export($test->getFirstName());
var_export($test->getLastName());
var_export($test->isAuthorized());
it displays the following error
Fatal error: Call to a member function getFirstName() on a non-object
in /login/securePage.php on line
17
When, however, I put
$login = new Login;
in front of
var_export($test->getFirstName());
var_export($test->getLastName());
var_export($test->isAuthorized());
It works! I dont' know what gives and if I am doing something wrong because even when I put
session_start();
instead of
$login = new Login;
but it still gives me the error
Fatal error: Call to a member function getFirstName() on a non-object
in /login/securePage.php on line
16
Could be a couple of things:
-You have to do a session_start() at the top of any page that uses sessions.
-With a serialized object (an object stored in a session variable), the object class needs to have been included anywhere it is being referenced.
Looks more likely to be that you didn't session_start()?
Also resource variables (database handles, file handles, etc) won't survive the serialization/deserialization that happens with session variables.
I think it has to do with the variable name. If I am not wrong, in your securePage.php, here is the code:
$login = $_SESSION ['usrData'];
var_export($login);
var_export($test->getFirstName());
It should be:
$login = $_SESSION ['usrData'];
var_export($login);
var_export($login->getFirstName());
Hope it helps.
It would be good practice to close the session before issuing the redirect (although I'd expect its unlikely that the session is not being written until after the browser requests the new page).
What does the line 'var_export($login);' within securePage.php generate? (comment out the calls which are causing the fatal error).

Categories