Problem with extended Email class |
[eluser]maikens[/eluser]
I am in the process of trying to debug a problem in my application where users are being logged out unexpectedly. I took it as an opportunity to configure the email aspect of the app as well. What I am trying to do is set up my application so that whenever a session is destroyed, I'll get an email with a dump of the session userdata, and the debug_backtrace(). It's not the best method, but it's a start My problem is that when I logout (and thus destroy the session), I get an error saying that the $email variable is undefined in the controller (even though I'd already autoloaded it). The error is: A PHP Error was encountered Severity: Notice Message: Undefined property: Dashboard::$email Filename: libraries/MY_Session.php Line Number: 43 MY_Session: Code: // ... MY_Email: Code: class MY_Email extends CI_Email { Anyone have any idea why this is happening?
[eluser]jakelehner[/eluser]
Autoload is loading the email library for Controllers and Models which have access to the default CI instance. Since you're creating your own instance of CI under $ci, you'll need to call $ci->load to load the email library under that instance. Aside from that, this doesn't sound like the most efficient way to troubleshoot the sessions expiring early. Troubleshooting sessions is tricky, but the email approach likely won't yield much. Figure out if your session is expiring when the 'sess_time_to_update' timer is expiring. That's pretty common and usually means a cookie issue or something is mis-configured. To test this, set your update value really low (in a dev environment) to something like 5 seconds. Log in, and start refreshing the page. If you're logged out in 5 seconds, you'll get a better idea of where to look.
[eluser]Aken[/eluser]
[quote author="jakelehner" date="1344367933"]Autoload is loading the email library for Controllers and Models which have access to the default CI instance. Since you're creating your own instance of CI under $ci, you'll need to call $ci->load to load the email library under that instance.[/quote] This isn't true. CI is loaded by reference, hence the get_instance() function (which, by the way, you don't need when extending the Session library, because there is already a $this->CI property available). The object will be the same, whether it's in your controller or a referenced object in a library. I did a quick test and the Email property was available to me no problem. You should post more code or try and simplify your code down to where it works, and see what might've gone wrong after that.
[eluser]maikens[/eluser]
Thanks for responding, jakelehner and Aken. I tried using $this->CI->email, but I got the same error. As it turns out, I did try and load the email library again, which got me further along, but I hit another error. That error was due to my using a port that my hosting provider does not allow me to send email through. The next thing is determining why I can't send to certain domains through port 25 (probably because they;re blocked because of spam), and which port I should use. Jake, thanks for your suggestion. I tried setting the update time to 5 seconds, but I was not logged out after refreshing after five seconds. I've scoured the internet about this problem, and mine seems to be fairly unique - it seems I've created a problem in how I handle checking sessions. I am going to wait until I am logged out randomly again, and see what is in the email. And hey, if you can think of any other reasons why sessions are being destroyed randomly, in a general context, throw them my way- I can use some ideas at this point! thanks again!
[eluser]CroNiX[/eluser]
There are many threads dealing with sessions being lost as it's not an uncommon problem. |
Welcome Guest, Not a member yet? Register Sign In |