Author Topic: Problem Viewing Cookies  (Read 284 times)

0 Members and 1 Guest are viewing this topic.

Offline eyalrosTopic starter

  • Irregular
    • View Profile
Problem Viewing Cookies
« on: May 30, 2007, 03:33:50 AM »
Hi Everyone,

I created a script in my computer and the cookies worked just fine, but now after I've uploaded it to a server for some reason php cannot read the cookies.

For Example, when I've uploaded this code:
PHP Code:
Code: [Select]
<?
setcookie("super_password", "hello", time()+3600, "/");
echo "the cookie is ".$_COOKIE["super_password"];
?>
It's returns nothing (not returning "hello". even after I've clicked "Refresh").

I tried the following things:
- I divided the script into 2 pages - one sets the cookie and reads it
- I checked the cookies in my browser and it's ok
- I used print_r($_COOKIE["super_admin]); instead of echo $_COOKIE["super_admin"];
- I removed the "/" domain section in the setcookie function

Does anyone knows how can I solve this problem?

Thanks! That's really important...

Eyal

Offline btherl

  • Guru
  • Addict
  • *
  • Matt is the best!
    • View Profile
Re: Problem Viewing Cookies
« Reply #1 on: May 30, 2007, 03:52:44 AM »
Have you verified that your browser is sending the cookie?  Storing it doesn't necessarily mean it'll send it.. though I'm not sure why it wouldn't.

You might want to try with firefox if you are using IE, and see if it behaves differently.

Offline eyalrosTopic starter

  • Irregular
    • View Profile
Re: Problem Viewing Cookies
« Reply #2 on: May 30, 2007, 03:59:18 AM »
Have you verified that your browser is sending the cookie?  Storing it doesn't necessarily mean it'll send it.. though I'm not sure why it wouldn't.

You might want to try with firefox if you are using IE, and see if it behaves differently.


I use firefox...  :-\

Offline DeathStar

  • Devotee
  • Gender: Male
    • View Profile
Re: Problem Viewing Cookies
« Reply #3 on: May 30, 2007, 03:59:36 AM »
Try this:
Code: [Select]
<?
setcookie('super_password', 'hello'", time()+3600, '/');
echo "the cookie is ".$_COOKIE[super_password];
?>
PHP and MySQL Programmer.
Code: [Select]
SQL = array('MySQL', 'PostgreSQL', 'Oracle', 'mSQL', 'Microsoft SQL');

Offline btherl

  • Guru
  • Addict
  • *
  • Matt is the best!
    • View Profile
Re: Problem Viewing Cookies
« Reply #4 on: May 30, 2007, 04:19:35 AM »
Aha.. well try installing the live http headers extension, so you can monitor what is sent.

http://livehttpheaders.mozdev.org/

Then at least you can be sure the cookie is being sent.. after that, it's a question of why you can't find it in php..

Offline eyalrosTopic starter

  • Irregular
    • View Profile
Re: Problem Viewing Cookies
« Reply #5 on: May 30, 2007, 05:01:17 AM »
Aha.. well try installing the live http headers extension, so you can monitor what is sent.

http://livehttpheaders.mozdev.org/

Then at least you can be sure the cookie is being sent.. after that, it's a question of why you can't find it in php..


Thanks! after I've installed it cookies started to work - but only in Firefox! not in IE - no matter what is the privacy level is - even if it's accepts all cookies!

Offline eyalrosTopic starter

  • Irregular
    • View Profile
Re: Problem Viewing Cookies
« Reply #6 on: May 31, 2007, 09:51:11 AM »
I found out something weird: IE accepts my cookie only if it's time being set to 0 like that:

setcookie("name", "value", 0, "/");

I cannot put something like "time()+3600" - it's don't accepts it.
Does somebody know how can I solve that problem?

Offline frost110

  • Fanatic
  • Gender: Male
  • /dev/null
    • View Profile
    • PHP
Re: Problem Viewing Cookies
« Reply #7 on: May 31, 2007, 10:26:13 AM »
Try this:
Code: [Select]
<?
setcookie('super_password', 'hello'", time()+3600, '/');
echo "the cookie is ".$_COOKIE['super_password'];
?>



I do not think this would work due to the fact that you generally cannot access cookies until the next page.

Are you trying to do this on Localhost, if yes let me know and I will post a tutorial for you.
Note: I do not test most of my code before posting, be aware!!!!

 Looking for an Awesome FREE PHP Editor? Eclipse with PHP-IDE Plugin - Best I ever used!

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.