Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem Viewing Cookies

    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:
    <?
    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

    This Problem Happens only in IE - no matter what the privacy level is (even if it's accepts all cookies!)

    Does anyone knows how can I solve this problem?

    Thanks! That's really important...

    Eyal
    Last edited by eyalros; 05-30-2007 at 09:39 AM.

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a setcookie(), is never available on the same page it has been set on. The page must be redirected or refreshed to see the cookie that was just set!

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,037
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Is your echo statement outputting anything, even just this part - "the cookie is "? If so, then stop using the short open PHP tag - <? and use the proper full PHP tag - <?php

    Edit: After re-reading your original post, that this only occurs in IE, dis-regard what I wrote above.

    However, you might have a cookie domain problem. Are you doing any url re-writing using a .htaccess file?
    Last edited by CFMaBiSmAd; 05-30-2007 at 02:34 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    setcookie("super_password", "hello", time()+3600, "/");
    Have you tried it without the last parameter?

    a setcookie(), is never available on the same page it has been set on. The page must be redirected or refreshed to see the cookie that was just set!
    The user already indicated two actions they took to make sure this was not the problem.

  • #5
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,037
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Any chance that the server's time setting or the time on the computer you are trying this on could be set incorrectly?

    The setcookie(...) is using the server's time, but once the cookie reaches the browser, the computer's time is being used to determine if the cookie has already expired. Try to set the expire time farther into the future and see if it starts working.

    This note is from the setcookie() description in the manual -
    expire is compared to the client's time which can differ from server's time.
    By using 0 for the expire time, all the comparisons between the server and computer time are eliminated, which is why I suspect time difference between the two is what is causing this.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •