SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Helsingborg, Sweden
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The syntax for setcookie is int setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]]).

    I'm currently developing some stuff here at home and thus my host is localhost.

    I can set path to '/' and it will work, but I can't figure out what to set domain to. I read somewhere that it requires at least two "dots" (.hmmm.com). If so, what should I do when my host is localhost?

    While we are on the subject. Does anyone know a smart way to generate the string for path and domain with the help of the Apache environment variables? Do you know what I mean? I want the users of my software to be able to edit the path and domain, but I want them to default to '/user/' and '.mydomain.com' if the script is located in 'http://mydomain.com/user/'. Here is one more example:
    http://www.mydomain.com/' would be '/' and 'www.mydomain.com'.
    "Some people play hard to get - I play hard to want."

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't set the domain to anything. You can set a cookie without putting anything for the domain.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Helsingborg, Sweden
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, but what if the people that install my script only want the cookie to be valid for their domain and a special path? I understand that I can skip the domain part when I'm working on the script at home, but when I upload it to the server I want it be right.

    What Apache environment variables are equivalent to path and domain in setcookie?

    Here are some of my apache vars:

    DOCUMENT_ROOT /kunder/d/designat.net/forum.revelj.com
    HTTP_HOST forum.revelj.com
    SCRIPT_FILENAME /kunder/d/designat.net/forum.revelj.com/test.php
    SERVER_NAME forum.revelj.com

    I tried using $DOCUMENT_ROOT (with and without an ending slash) for path and SERVER_NAME for domain, but it doesn't work.
    "Some people play hard to get - I play hard to want."

  4. #4
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the config file (i assume there is one) show a variable like
    $cookie_domain="";
    then put a note next to it saying what it can be changed to.

    Just a suggestion
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Helsingborg, Sweden
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I think I'll have to do it like that. There just doesn't seem to be a foolproof way of extracting the path and domain from the apache environment variables. I would prefer to do that. Then the administrator could change the path and domain later in the admin interface I'm planning to write. I wanted to make the installation as simple as possible. I want any schmuck to be able to install it. Oh well, I guess I'll have to settle for the "config file way".

    Thanks for the help anyway!
    "Some people play hard to get - I play hard to want."

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    By default, cookies are valid for the current domain only. You don't need to specify a domain to do this.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •