Welcome Guest, Not a member yet? Register   Sign In
Problem with setting cookies in CI
#1

[eluser]Unknown[/eluser]
Hi all

I need a value to be available in one of my plugins(FCKEditor-to set the root folder dynamically,for uploading files , in the config.php file of the connector).
I am trying to make use of cookies for that.
I used set_cookie method of CI.
But it is not working.( i am able to use session cookies)
When i used the native setcookie method the path was set to the file location from where i set even if i gave the path as '/'.
Please help me on this.


Or is it possible to access session outside the application. i.e. in plugins?
Cheers.
#2

[eluser]pvijayanands[/eluser]
Hi i have set the cookie for my project... I am using the PHP session library.. First we have to include the PHP session library....

set the cookie

login page controller:

Code:
$this->phpsession->save('u_member','1');
setcookie('u_member','1',0,'/');

Header page view :

Code:
if( isset($_COOKIE['u_member']) && $_COOKIE['u_member'] == '1' )
{
  if($this->phpsession->get('u_member'))
  {
        Your Code Here.......
  }
}
elseif($this->phpsession->get('u_member')!='0')
{
    $this->phpsession->save('session_msg',"Your session has expired. Please login again.");
    redirect('logout');
}
Logout Controller:

Code:
// Checking Session
$session_msg = $this->phpsession->get('session_msg');
setcookie('u_member','',0,'/');
if(!empty($session_msg))
{
echo  $session_msg;
}




Theme © iAndrew 2016 - Forum software by © MyBB