Welcome Guest, Not a member yet? Register   Sign In
Session gets lost and won't show on main page?
#1
Question 

Hi,

I have a problem, it's the same if I use the session library or not the same thing happens.
I have my helper function loaded that when it's called it sets the session for the notification that needs to be displayed:
PHP Code:
function NotyI($string)
{
 
 $noty = array("text" => $string"type" => "information");
 
 $CI =& get_instance();
 
 $CI->session->set_userdata('noty',$noty); 
 
 //$CI->session->mark_as_flash('noty');

So I thought at first that this mark_as_flash made the problem, but even without that it does not work.
I have a controller that calls this function NotyI when then notification should be spawned.
PHP Code:
NotyI("User is already registered!");
header("Location: " $this->config->base_url());
exit(); 
The helper functions and sessions library are loaded trough autoload.php and they are called without a problem if I vardump the $_SESSION variable after the set_userdata everything is there. Then when the function exits and the header is called the controller that gets loaded does not show any session data like the session is not present I only see the codeigniters __ci_last_regenerate.

What can cause this problem?
Thanks for your help!
Reply
#2

(This post was last modified: 01-12-2016, 12:58 PM by Vita.)

Session works as expected, but I had an error in the code. I've set the session while the app was running under localhost domain after that, the header redirects to 127.0.0.1 and the session is then not valid on that domain. The above problem is solved by making sure that you set and check the session under the same domain!

Another question is there a way not to match an exact domain, but rather match multiple domains/subodmains?
Reply
#3

Not really connected to your question, but why do you use the codeigniter instance in a helper?
Reply
#4

(This post was last modified: 01-13-2016, 04:43 AM by Vita.)

It's because I need to access the session library.The library is loaded via autoload.php. I can't use it without the CI instance. I wanted to use the flash session that is implemented in CI session library because I need the session for only one request.

I could have set the session manually by using the $_SESSION var.

Is there a way to use the loaded lib without the CI instance?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB