Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setcookie doesn't work

Status
Not open for further replies.

axtec

Programmer
Dec 12, 2001
21
0
0
US
I have used setcookie many times in the past, but I just re-installed php and apache. Now, when I use setcookie, the cookie never gets set (or at least I can't access it with $HTTP_COOKIE_VARS[];). Can anyone point me to where I need to make an adjustment. I think it's either in my php.ini or apache conf file. PHP4 Apache2.

Thanks for the help.
 
Can you verify that the HTTP header to set the cookie is being sent?
 
I'm not sure how to verify that. I can send Header requests (Header();) though, and that works fine.
 
Well, I always test cookie functions by telnet to port 80 then issuing the GET directive by hand. It lets me see that I've got the cookie settings right.

Other problems with cookies have to do with the path and domain settings for a cookie. Are you using those?
 
this is what it looks like in my php.ini:

session.use_cookies = 1
session.name = PHPSESSID
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
 
Those configuration options are specifically used for the cookies the session handling subsystem of PHP uses. They don't apply here. Or are you trying to implement cookie-based session-variables on your own?

How, exactly, are you invoking the setcookie function?
 
I do a database query, and if the query matches, I do this:
setcookie("Login", "true");
 
I'm actually trying to set two cookies. Could it be that in my new installation of php and apache i'm only allowed to set one cookie now? Is there a config somewhere to set the number of cookies you can set?

Thanks for all your help so far.
 
No, you can set quite a number. Netscape's cookie spec states that a browser should be able to support 20 cookies per domain.

I think I know what the problem is. Are you setting a path for the cookie?

If you do not, then the browser should assume that the cookie was intended only for the page that set it. It will not be available to any other page.
 
where do you set the path for the cookie? httpd.conf, php.ini, or elsewhere?


In php.ini my cookie path setting looks like this:
session.cookie_path = /
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top