Welcome Guest, Not a member yet? Register   Sign In
set_cookie, get_cookie issues
#1

[eluser]jared4444[/eluser]
I can't get set_cookie to work in codeigniter.
I created a model and have two function calls setordercookie, and getordercookie.
I also added regular php cookies to these functions which do work.

My model also has:
$this->load->helper('cookie');.

My controller calls:
$this->order_model->setordercookie();
$this->order_model->getordercookie();

The output on my first run is:
No newcookie
No oldcookie

The output on my second run is:
No newcookie
oldcookie value

Config file:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";

Here is my url (I did not take out the index.php, I had an issue with the .htaccess):
http://localhost/pcwf/index.php/order/processorder/

Here is the code:
function getordercookie()
{
if (get_cookie('newcookie') == false)
print "No newcookie<BR>";
else
print get_cookie('newcookie');

if (isset($_COOKIE['oldcookie']) == false)
{
print "No oldcookie<BR>";
}
else
{
print "<BR>" . $_COOKIE['oldcookie'];
}
}

function setordercookie()
{
setcookie('oldcookie','oldcookie value');

$cookie = array(
'name' => 'newcookie',
'value' => 'newcookie value'
);

set_cookie($cookie);
}
#2

[eluser]Colin Williams[/eluser]
I've never had any luck with cookies without being on a VirtualHost. Browsers seem reluctant to store cookies for the localhost domain.




Theme © iAndrew 2016 - Forum software by © MyBB