SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Cookies

Hybrid View

  1. #1
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having trouble getting a cookie to set for Netscape. It works fine in Explorer but doesn't seem to work in Netscape. Here is the code to set the cookie:

    //$cli_user is the check box to remember the username ($cli_uname)

    if ($cli_ruser == "YES") {
    setcookie( "cu", $cli_uname, "time()+3600", "/", "domain.com", 0 );
    setcookie( "ru", "YES", "time()+3600", "/", "domain.com", 0 ); }
    else {
    setcookie( "ru", "NO", "time()+3600", "/", "domain.com", 0 );
    setcookie( "cu", "", "time()+3600", "/", "domain.com", 0 ); }

    I then retrieve the cookie with this code:
    if ($ru == "YES") {
    ... Place the username ($cli_uname) in a textbox
    } else {
    ... Leave the text box clear
    }
    if ($ru == "YES") {
    ...Re Check the box
    } else {
    ...Leave the checkbox unchecked
    }

    Why isn't Netscape taking this?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I saw this reader comment in the manual @
    http://www.php.net/manual/en/function.setcookie.php
    I wander if this is the problem?
    From: http://developer.netscape.com:80/doc...de/cookies.htm
    The document says that the domain name must have at least two periods before the cookie can
    be set and the cookie has to be set with two periods. I have to redirect everyone to the
    www.domain.com before setting the cookie.

    by the way, why do you wrap the times in "", ie;
    "time()+3600" (I'm not very familiar with cookies)

  3. #3
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure enough change domain.com to .domain.com and it works. And about the "" they are unnessecary I placed them accidentally.

    Thanks,

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a heck of a time with them in NS... until I tried the period and it worked... however, you need to realize that this will ONLY work with the www. in front of the domainname... if they leave it out... you're screwed. So, to fix that problem, I used this, and included it at the top of every page of my site that "might" use cookies...

    Goes at the top of each page:
    PHP Code:
    require "check.inc"
    the code for check.inc
    Code:
    <?php
    if($HTTP_HOST != www.domain.com){
    header("Location: http://www.domain.com");
    }
    ?>
    there.. that makes sure that the www. is in front of your domain...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    SitePoint Enthusiast pedershk's Avatar
    Join Date
    Mar 2001
    Location
    Oslo, Norway
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a pointer - according to my bible, Professional PHP programming by Wrox press (yes, I know - shameless plug - but it's the best book on PHP out there IMHO), if you set / read cookies with .domain.com instead of www.domain.com, the cookie will be valid/usable on *all* hosts in .domain.com, for example both on www.domain.com and member.domain.com. So there is a slight difference.
    **Henning K. Pedersen**
    Forbrukerkraft Norway A/S


Bookmarks

Posting Permissions

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