Codeigniter session not being maintained after certain pages - php

I am using PHP native session instead of CI session library.CI version ci-2.2.
When i login to admin, it sets the session.I can go to any next page which requires session.But when when i go to another page after that the session is lost.It works fine locally and on many other servers for which I use CI.
As an example.
I login to admin.It takes me to dashboard.Then i go to some listings page.It works fine.Thereafter I click on say some add new page , session is lost.

if any of your controller extends the admin controller make sure the session check is done on the admin controller itself.
so that any controller that extend it will inherit the check.
Hope this helps.

Related

Do not check session on specific page

I am using sessions to check if the user is logged in. In my project, there are some pages, where session check is not required i.e user can access it without logging in. How I disable session check on selective pages? Instead of writing say session_check on every page that needs session, i want to know if there is a way to implement no_session_check() on selected pages. As the number of pages that require session check are more than pages that do not work. I am using codeigniter. Thanks
First you created the session checking function in library file .. if u want session on that controller just call that library function..
Refer this link:

Sessions in CodeIgniter hinder each other

I'm making a CMS using CodeIgniter. I'm using modules to separate the admin part of the site from the normal site. I make use of session to store some data, this is working great but i got 1 problem.
When i login in the Admin panel it makes a session so I know I’m logged in. When I go to the normal site and return to admin and refresh my page I’m logged out. It seems like when I go to the normal site it first clears the session or it overwrite the old session. I think this comes because of the session name used by CodeIgniter.
now my question :p
Is it possible to set different session names for the admin module and the normal site?
I hope I have made ​​myself clear
Best practice if you handle session with db in CI
yes it's possible please use seperate session for both and on logout unset seperate session what session you want to unset.
like you create session for front:-
$this->session->set_userdata('user_account_login',$data);
on logout you need :-
$this->session->unset_userdata('user_account_login');
same for admin but in different var :-
$this->session->set_userdata('admin_account_login',$data);
on logout you need :-
$this->session->unset_userdata('admin_account_login');

Session satus is not set in some page of php

I am using Elgg Application, Inside FB connect plugin i am starting Session and setting some variables in the same folder i am accessing this session attributes its working fine..
But i included one more php file, after log-in if i directly call this page through url session_status is 1 but in other two folders its is set...
How to set session here also, their should be any link between pages to session variables
can any one help...
Fb_connect folder
str= "var/www/elgg/mod/fb_connect
import-contact-plugin-str="var/www/elgg/mod/importer.
new php file i added
url=var/www/elgg/engine/sample.php
When you work with Elgg, you shouldn't change its core. Almost everything can be done by plugins, and that's the preferred way of working with Elgg.
Elgg sessions are kept in database and session start is called on system boot event. When you're in plugin context however, the session is already in place, no need to to additional session_start call.
So if you decide to go on modifying the core, you should run your logic from callback registered to boot system:
elgg_register_event_handler('boot', 'system', YOUR_CALLBACK);

Compare cookie on site load

I am using Code Igniter and I am implementing a remember user functionality.
Basically, from another stack overflow post, I implemented this the right way where I generate a random string for that user, save it in the database AND in a cookie. On site load, I check for that cookie, if that cookie is found I check it in the database. If it is found in the database then recrease the session for that user.
The problem I am having is when I load the site. I am getting the value of the cookie and I am also getting the correct response from the AJAX call. However, I have to click on a link in order for the session to get recreated (such as menu is displayed for logged in user and so on).
I am thinking that I am recreating the session AFTER the index method of the main controller is called. How can I get around this in Code Igniter? Where can I put this code which preferably gets run first thing on every page? As for instance I also want to recreate the session if the user enters the site's contact us page instead of the home page.
Many thanks in advance.
CodeIgniter allows the developer to create hooks which are called at different moments before the controller method is called.
Here is a short description of how to use hooks:
http://codeigniter.com/user_guide/general/hooks.html
If you want to access the session, I would recommend to use a post_controller_constructor hook, which is called after the controller constructor is executed, but before the action method is called. ( access the CI session in a pre controller codeigniter hook )

CakePHP Auth.redirect not being written

I have followed the authentication tutorial in the cakephp documentation and created a working login system.
One thing I'm trying to do is have the user redirected to the action they were trying to access initially when not logged in, after they complete login.
I believe the page they were visiting is supposed to be written to Auth.redirect within the session by the startup function in the Auth component, however this doesn't appear to be working.
In my users controller I have added the following to the beforefilter:
$this->Auth->allow('add', 'login');
Therefore when trying to access the edit action I'm redirected automatically to the login action.
In the login action, I've included:
debug($this->Session->read());
debug($this->referer());
This is outputting the session information, and in this session there is no mention of Auth.redirect so neither the Auth function or myself is unable to use this to redirect the user with.
I've tried using $this->referer but for some reason when being redirected automatically by the auth function the referer isn't being tracked either.
Does anyone know a reason why auth.redirect might not be being written and why $this->referer isn't being populated when redirected by the auth function?
I must note I am on a windows machine using WAMP. However my add action redirects to login after success and debug($this->referer()); picks up the redirect URL when this occurs so the headers must be working fine.
Further Notes:
I've identified the issue with CakePHP by looking through the sessions stored in the database.
It seems that the auth.redirect is stored in the session, however for some reason a new session is generated when the user is redirected clearing the previous data.
Is there anyway to stop CakePHP creating new session ids for users?
I've identified the issue as to why auth.redirect wasn't working.
I had set a custom session cookie name in core.php, for some reason the session component doesn't work with the custom cookie name and therefore creates a new session on every page.
If you are experiencing problems with sessions and you have a custom session cookie name, reset it to default and it will work.
I will be submitting this as a bug to CakePHP.
Further Note
I identified the issue was occuring because of a . in the cookie name, without this . the custom cookie name performs as it should.

Categories