Welcome Guest, Not a member yet? Register   Sign In
Can't set cookie
#5

[eluser]veledrom[/eluser]
Thanks for replying.

I've changed example and added redirect(); and added another function to read the cookie but this example doesn't work either. How do I modify this example make it work?

Sorry for being pain.

VIEW
Code:
<p>
<a href="&lt;?php echo site_url('welcome/set_language/english'); ?&gt;">English</a>
<br />
<a href="&lt;?php echo site_url('welcome/set_language/spanish'); ?&gt;">Spanish</a>
</p>
<br />
<p><a href="&lt;?php echo site_url('welcome/get_language'); ?&gt;">Get Language</a></p>

CONTROLLER
Code:
class Welcome extends CI_Controller
{
var $cookie_name = 'language';

public function __construct()
{
  parent::__construct();
  
  $this->load->helper('url');
  $this->load->helper('cookie');
}

public function index()
{
  $this->load->view('welcome_message');
}

public function set_language()
{
  if($this->uri->segment(3) != false)
  {
   $cookie = array(
       'name'  => $this->cookie_name,
       'value'  => $this->uri->segment(3),
       'expire' => '86500',
       'domain' => '.language.com'
       );
  
   set_cookie($cookie);
  
   redirect(null, 'refresh');
  }
}

public function get_language()
{
  if (! get_cookie($this->cookie_name))
  {
   echo 'Cookie not set';
  }
  else
  {
   echo get_cookie($this->cookie_name);
  }
}
}


Messages In This Thread
Can't set cookie - by El Forum - 10-26-2012, 02:39 AM
Can't set cookie - by El Forum - 10-26-2012, 05:46 AM
Can't set cookie - by El Forum - 10-26-2012, 08:12 AM
Can't set cookie - by El Forum - 10-26-2012, 08:15 AM
Can't set cookie - by El Forum - 10-26-2012, 08:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB