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'.
Don't set the domain to anything. You can set a cookie without putting anything for the domain.
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:
I tried using $DOCUMENT_ROOT (with and without an ending slash) for path and SERVER_NAME for domain, but it doesn't work.
In the config file (i assume there is one) show a variable like
then put a note next to it saying what it can be changed to.
Just a suggestion
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!
By default, cookies are valid for the current domain only. You don't need to specify a domain to do this.