Welcome Guest, Not a member yet? Register   Sign In
set_cookie not setting cookie
#1

[eluser]pickledegg2[/eluser]
I know there are a few posts regarding this, but nothing conclusive. For some reason the set_cookie function just doesn't work, so I've had to use the native setcookie(). Can't see why, I just tried a name & value, but no cookie. I'm all PHP5'ed up.

Anyone have any ideas? thanks.
#2

[eluser]dtrenz[/eluser]
I doubt you are having the same problem I had, but when iFrame-ing in a page (in IE) that tries to set a cookie you need to set a P3P header to tell IE to allow it.
#3

[eluser]Jim Higgins[/eluser]
Anyone figure this out? I have been digging around for quite a while and have found many posts of users having set_cookie problems, but have yet to find one solution.

Of course, I am also having this problem now. Sessions work fine, but the set_cookie will just not work.

... cookies are enabled, helper is loaded, etc.
#4

[eluser]richthegeek[/eluser]
I used to have this problem with setting cookies on my localhost - both via PHP and JavaScript - IE just wouldn't allow it (it seemed the server wasn't even sending it)

Perhaps try your same code on 2 or more installs and see if it re-occurs.
#5

[eluser]Jim Higgins[/eluser]
After a while I suspected it might be my localhost so I moved it to my shared hosting environment and experienced the same issue. It's just not setting the cookies and I don't really know why.
#6

[eluser]richthegeek[/eluser]
try the basic PHP setcookie rather than the CI version? Perhaps it is some odd form of code CI uses?
#7

[eluser]Jim Higgins[/eluser]
Yeah. The native setcookie for PHP works just fine... which is why this is so frustrating. I can do without the CI Helper, but I'd love to also figure out why it doesn't work. Guess that's why I'm still a Newbie.

Thanks again for your support.
#8

[eluser]richthegeek[/eluser]
maybe delving into the code might work - it's probably something weird to do with the "allowed directories" directive...
#9

[eluser]internut[/eluser]
having this issue right now as well... i find myself trying to use helpers probably when I should not be using them....

i feel like writing orig PHP code is backwards when using the framework. Am I wrong?
#10

[eluser]Jim Higgins[/eluser]
Yeah, I wanted to use the built in CI functionality as well, but in the end, the regular PHP is almost identical and I couldn't waste anymore time on it. I have yet to see a real explanation for why the CI set_cookie doesn't work all of the time. I've seen lots of people with the issue and lots of suggested reasons, but when it came down to it (for me at least) it seemed to just be some weird CI thing. As soon as I did the exact same thing with the PHP version, it worked fine. One thing to note is I think the parameters are in different order.

Code:
setcookie('my_cookie_name', '', -1, '/');

Another thing... I am able to use the input->cookie to retrieve my cookies that I set with the regular PHP.

Code:
$this->input->cookie('my_cookie_name')

but, the weird thing was I could not get them with this method on in my index (default controller)... only on every other controller in my application. So, in my default controller, I am using

Code:
$my_cookie = $_COOKIE['my_cookie_name'];

Lastly, make sure you still run xss clean on your cookie data if you use the PHP version.




Theme © iAndrew 2016 - Forum software by © MyBB