Click to See Complete Forum and Search --> : problem setting cookie
rschmitt
05-16-2001, 02:32 AM
Hi there,
I'm having problems setting cookies on my local Win200o machine running PHP4 and Apache.
I have no problems using sessions, and my code works when I run it on a remote server (i.e. the cookie is set), but no cookie appears on my local machine.
I assume it must be a setup problem with my current configuration, but I don't know where to look!
Can anyone help?
if you are using sessions, no cookies are stored locally on the user's system, they are kept on the server. else, just check if the cookies are available by trying to echo the cookie value.
rschmitt
05-16-2001, 05:45 AM
Thanks for your reply, but you misunderstand.
I AM actually trying to set a cookie using setcookie(), and my code works perfectly on another server. The cookie is set and I can view the actual cookie file on my pc.
The problem arises when I try to run this script on my LOCAL server (Win2000, Apache, PHP4). Then the cookie does not set.
Any ideas?
I had a similar problem tring to test a few things.
Are you using "localhost" to talk from your
local browser to your local server system
and back again to your local browser ?
rschmitt
05-17-2001, 12:50 AM
Actually no... I'm running a Virtualhost.
I've just tried running the script through "localhost", but it has no effect... the cookie's still not there.
Any ideas?
Ya know, I am having the same problem with my local server. I am running Win NT 4.0 SP6a with IIS 4 and PHP 4.
It just won't set the cookie. I don't know if I'm doing anything wrong, but I would sure like to know if anyone found a solution.
Yep - me too : One small difference, that on checking the cookie sent to the browser in JS, is that the cookie *is* returned but it only contains the PHP session ID : attempting to set own values fails.
Config : PHP 4.0.5, Apache 1.3.12, Windows 2000
I'am have the same trouble right now. This is my testing code in one page:
setcookie("id01", 200);
echo '<br>cookie='.$id01;
echo '<br>cookie='.$HTTP_COOKIE_VARS["id01"].'<br>';
The cookie only shows up when I click the "refresh" button of the browser. I don't know how to make it available at the first time the script is executed.
Hi -
Well, at least I can solve that problem for you (if you haven't done so already) : it's to do with the way cookies work.
A cookie is set by a 'get' request from a client (browser), on the server. The *first* time the browser requests a page from that domain (and sub-directory if specified), the server will send the cookie *to* the browser.
The browser then sends the cookie back to the server *next time* it visits. That's actually when your cookie data becomes available to the server - when its returned by the browser.
Any q's please feel free to mail me.
Just recently there have been more replies to my message posted almost a year ago now. I thought I'd follow up on my original posting, because I finally did manage to get my problem sorted out.
As it turns out, it all comes down to syntax. The ONLY way I can set a cookie on my Win2000/Apache/PHP4 installation is like this:
setcookie('cookieName', '$value', 0, '/', '', 0);
or
setcookie('cookieName', '"value"', 0, '/', '', 0);
or to kill the cookie:
setcookie('CookieName', '', 0, '/', '', 0);
The third argument (0) specifies that the cookie should expire when the user closes his browser. So replace this value with something like time()+7776000 to have it expire after 90 days or something.
Well, Thanx bro. I had serious problems with this too. I would never though that in WIN/APACHE/PHP for cookies one shoul use empty domain name instead of localhost or something like that.
Thanx again.
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.