By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

php cookie acting strangely

JnrJnr
P: 88
Hi all, I have a little testing site where I want to test my problem.
The site has 3 pages:
Home, Account, Cart, and a menu to navigate to them.

What I do is:
On the Home page I set the cookie on submit button click. (the page refers to itself)
I then navigate to another page (Account) and check if the cookie is set. And it is.
Then I navigate to next page (Cart) and check if the cookie is set. And it is.

The problem:
When I go back to the page where I originally set the cookie, it always dispalys that the cookie has not been set.

Expand|Select|Wrap|Line Numbers
  1. setcookie('myCookie', 'Val', 0, '/', false); //this is done on Home page
  2. //The following is done on all pages...
  3. if(isset($_COOKIE['myCookie']))
  4. {
  5.   echo($_COOKIE['myCookie']);
  6. }
  7. else
  8. echo('not set');
Note: the problem occurs always from the page the cookie was set. Also this works fine in FireFox but not IE
Can anyone share some knowledge please?
Nov 2 '11 #1
Share this Question
Share on Google+
4 Replies


zorgi
Expert 100+
P: 431
You are checking in $_POST. Shouldn't you be checking within $_COOKIE

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['myCookie']))
Nov 3 '11 #2

JnrJnr
P: 88
Hi zorgi, you are right I made a mistake when I posted the question. (I will fix it)
It is suppose to be $_COOKIE[''] but it was still not working in IE.
I checked for help everywhere and tried a lot.
The only thing that I could make sense of is that I am using a local domain name (local server) to test and develop.
Apparently IE's cookies dont always function properly when using local servers.
So I installed IE 9 just for development purposes and its working fine now. Thanx for the code correction though!
Nov 4 '11 #3

zorgi
Expert 100+
P: 431
I just checked on my localhost with IE8 and it works fine.
Nov 4 '11 #4

JnrJnr
P: 88
Thanks zorgi. As I said Im not entirely sure what the problem was.
Nov 4 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.