Welcome Guest, Not a member yet? Register   Sign In
Sessions - Not Working
#21

There's no way to disable the locking, but that shouldn't be a problem for AJAX requests ... they just won't be really asynchronous. Other than the redirect happening before the login request is executed, I can't think of a reason why the session would be empty.
Reply
#22

(06-29-2015, 03:18 AM)Narf Wrote: There's no way to disable the locking, but that shouldn't be a problem for AJAX requests ... they just won't be really asynchronous. Other than the redirect happening before the login request is executed, I can't think of a reason why the session would be empty.

@Narf: I have narrowed it down to what it loosing the session, I have tried a couple of options to prevent this from happen with some Stackoverflow help howevere nothing seems to be working so I thought I would see if you have any input on this.

Basically on login, because use's an ajax request, after the login is successful it redirects to the dashboard, the session is fully populated with the data need until I redirect, the way I have set it up and because its using AJAX is to redirect with
Code:
public function redirect($Uri, $Send301Header = false)
{
 if ( !$this->isRemoteEvent() )
 {
   redirect($Uri);
 }
 else
 {
   $output = "<script type='text/javascript'>";
   $output .= "(function(){window.location='".$Uri."';}).delay(100)";
   $output .= "</script>";
   echo $output;
 }
 die;
}

In this instance it is using the ELSE clause of the if/else which is where the session becomes reset.

Thoughts?
Reply
#23

Yep ... unless you call session_write_close() prior to doing that redirect, the session cookie is never sent to the browser, because you've already started the output and you can no longer send a header. That's why you shouldn't directly echo from a controller/model/library and always use the views instead.
Reply
#24

(07-03-2015, 01:34 AM)Narf Wrote: Yep ... unless you call session_write_close() prior to doing that redirect, the session cookie is never sent to the browser, because you've already started the output and you can no longer send a header. That's why you shouldn't directly echo from a controller/model/library and always use the views instead.

Cheers Narf, more or less the same as what solutions are on the web, after trying the  
Code:
session_write_close()
before the redirect it didn't seem to work as planned and the session still dropped.

Will look a bit deeper see if I can get it to work.

Thanks
Reply
#25

(06-25-2015, 10:34 AM)Wouter60 Wrote: You are wrong about loading the session as a driver.
Just like before, it must be loaded as a library:
PHP Code:
$this->load->library('session'); 
Check the documentation for that.

The tricky part is configuring the session settings.
I didn't get it working with $config['sess_driver'] = 'files';
Therefore, I switched to $config['sess_driver'] = 'database';  and I added a ci_sessions table to my database.
No problems with sessions since then.

I'm trying to use sessions in database on v 3.01 and it is not working. I am getting the error

A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'' at line 2
SELECT `data` WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 160

I am using mysqli
Reply
#26

(This post was last modified: 11-15-2015, 02:29 AM by sv3tli0.)

(11-14-2015, 12:29 PM)mike7418 Wrote: I'm trying to use sessions in database on v 3.01 and it is not working. I am getting the error

A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'' at line 2
SELECT `data` WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 160

I am using mysqli

at config.php there is description just before session configuration:
Quote:sess_save_path: 
....
| For the 'database' driver, it's a table name.
| Please read up the manual for the format with other session drivers.

At the moment you haven't set its name and for that reason there is NO FROM .. in you session DB queries ..
Best VPS Hosting : Digital Ocean
Reply
#27

(11-15-2015, 02:26 AM)sv3tli0 Wrote:
(11-14-2015, 12:29 PM)mike7418 Wrote: I'm trying to use sessions in database on v 3.01 and it is not working. I am getting the error

A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'' at line 2
SELECT `data` WHERE `id` = '79a66a6e1e7cb4dcb58794a078629cc5532f2e6b'
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 160

I am using mysqli

at config.php there is description just before session configuration:
Quote:sess_save_path: 
....
| For the 'database' driver, it's a table name.
| Please read up the manual for the format with other session drivers.

At the moment you haven't set its name and for that reason there is NO FROM .. in you session DB queries ..


I missed that line in the user guide. Thanks!!!! It works now...
Reply
#28

@iD30:

I am using sessions as well. I have autoloaded the 'session' in the libraries in the autoLoad.php.

The difference I have is that I have:

$config['sess_save_path'] = $_SERVER['DOCUMENT_ROOT'] . '/session_cache';

in the config.php. For the rest I am doing the same thing as you do and it is working fine.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB