1
votes

I ve been having some problems with setting and getting COOKIES. I have a page outside an iframe where i set a cookie and then redirect on to facebook, where i get the COOKIE previously set and store in a DB. This user path works fine, except that a user can arrive to the facebook page (tab) directly, where i need to set a cookie there if one is not set.

I know that in certain browsers a P3P policy should be present when setting a COOKIE so i use: header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); which does its job for IE, but i have noticed that the problem is not only IE related.

One possible problem might be that i set and try to get the COOKIE on the same page directly without refreshing the page after the COOKIE is set ??? Whould the iframe affect how COOKIES are set through PHP ?

Any thoughts?

Thanks in advance.

1
try $_COOCIE['somename'] = ... instead of setcookiek102
You should be careful with setting P3P headers because they are a potentially legally binding promise of how you are going to treat your use data. Normally they should link to an XML P3P document which should make legally verifiable assertions. Unfortunately there is no other way around getting IE to allow you to set cookies in an iFrame. If you didn't include the P3P header you would need a cookie-less solution.Robin Winslow
Cookies should work fine in all other browsers. And you should be able to check for a cookie and set it in the same set of PHP code, as long as you haven't already sent header.Robin Winslow
@Robin Winslow, i use P3P headers before checking if the COOKIE is set so that wont work would it?Nick Jones

1 Answers

0
votes

Cookies should work fine in all non-IE browsers. And you should be able to check for a cookie and set it in the same set of PHP code, as long as you haven't already sent headers. The server will receive a request, with a load of headers possibly including your cookie.

You PHP code should be able to then check these cookies, and set a load of headers to send back to the user's browser. However, it is quite easy to accidentally send some stuff back to the user's browser before you've finished setting the headers, in which case setting cookies after that point won't work. For example, if you put a closing PHP tag ?> in a file, and then a new line or a space, that will get sent back to the user's browser at the point that code is run, which will send back the response headers, meaning they can't be modified after that point.

You should be getting a "headers already sent" error though.

Try running:
http://www.php.net/manual/en/function.headers-sent.php

http://www.tech-recipes.com/rx/1489/solve-php-error-cannot-modify-header-information-headers-already-sent/