[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="<?php echo site_url('welcome/set_language/english'); ?>">English</a>
<br />
<a href="<?php echo site_url('welcome/set_language/spanish'); ?>">Spanish</a>
</p>
<br />
<p><a href="<?php echo site_url('welcome/get_language'); ?>">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);
}
}
}