#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    62
    Rep Power
    15

    Problems setting cookies with a path and domain


    I'm using the following functions to set cookies on my board (which is currently running on an apache server on my Redhat7.3 laptop):
    PHP Code:
    function setMyCookie($cookieName$value){
        global 
    $INFO;
        
    $expire time()+60*60*24*365;
        
    $name $INFO['cookie_prefix'].$cookieName;
        
    setcookie($name$value$expire$INFO['cookie_path'],$INFO['cookie_domain']);
      }
      
      function 
    getMyCookie($cookieName){
        global 
    $INFO;
        
    $name $INFO['cookie_prefix'].$cookieName;
        return 
    $_COOKIE[$name];
      } 
    where the two $INFO variables are set elsewhere as (for now) domain = "localhost.localdomain" (I've also tried "localhost.localdomain." and "127.0.0.1") and path = "/ibb" - to run the script I use http://localhost.localdomain/ibb/index.php, with the prefix = "ibb_"
    Now I've got an invisionboard forum installed at /ibf/index.php, and it sets cookies OK, but my scripts won't set cookies. I don't get any errors returned, I don't supress the messages, the function is being called (I put an echo in there at one point to check) but when my script comes to reading the cookie it doesn't exist. Also, checking through my cookies using the Mozilla "Manage Cookies" feature, the cookie doesn't seem to exist.
    I'm not doing anything daft like blocking cookies (like I said other software on my personal apache server sets cookies with no problems) so does anyone have a clue why the cookies might not be working?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    62
    Rep Power
    15
    No one? :\
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    108
    Rep Power
    15
    Check that the entire $INFO array is the way you want it by doing a print_r($INFO).

    That must be your problem, unless your problem is on the client side, check that you even allow cookies. There may also be a problem with the fact that your domain is localhost. Try uploading the script to another server and seeing if it works on antoher domain.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    62
    Rep Power
    15
    I've echo'ed the contents of the array before now, and it all looked correct. It ain't my server, because one of my other scripts (an invision board) is setting cookies fine - that covers it being client side too. Thats whats confusing me. Everything looks fine, but it can't be cos cookies set fine from the Invisionboard, but not from my script.
    I'll take a look though

    [edit] arrrggghh, this is confusing. I set Mozilla to warn me when someone tries to set a cookie, this site (devshed) warns me, my script doesn't. Whats even better, I add output (buffered) depending on whether it succeeds or fails, they all return a success how can it successfully set a cookie and yet not prompt me? and where do they go? cos they ain't in my Mozilla list of cookies.
    OK, so using just the first three variables in the setcookie method returns true and sets the cookie properly. using all of the variables returns true, but the cookie doesn't appear. It just doesn't make sense
    Heres what the print_r gave me:
    Array
    (
    [site_name] => dotFootball site
    [site_name_short] => .Football
    [site_url] => http://localhost.localdomain/ibb/
    [site_contact] => x@y.co.uk
    [site_skin] => 1
    [skin_root] => skin/
    [site_lang] => en
    [main_mod] => 1
    [login_time] => 15
    [site_domain] => dotFootball.com
    [version] => 1.0
    [cookie_prefix] => df_
    [cookie_path] => /ibb
    [redir_pause] => 5
    [cookie_domain] => localhost.localdomain.
    [use_COPPA] => 1
    [confirm_reg] => 0
    [guest_group_name] => Guest
    [site_key] => abc123
    [allow_multi_emails] => 0
    [var] => Array
    (
    [modfile] => index
    )

    )
    which looks fine to me
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    62
    Rep Power
    15
    OK, having tweaked and twiddled with Invision Board, it appears it may be bypassing cookies through other means (ie just a session ID passed as a parameter).
    So, to clarify what the problem is begining to look like, if I use setcookie(name, value, expire), the cookie sets ok, it returns true and appears at the client end.
    If I use setcookie(name, value, expire, path, domain) with path="/ibb" and domain="localhost.localdomain." for a script in localhost.localdomain/ibb/ PHP returns true, but the cookie never appears. Thats simply replacing the three param version with the five param version.

IMN logo majestic logo threadwatch logo seochat tools logo