NYCPHP Meetup

NYPHP.org

[nycphp-talk] setcookie Pt. III

Patrick Hunt pat at vote.com
Fri Sep 5 20:37:55 EDT 2003


Phil,

Please be patient with me while I ask a silly question: 
Exactly how are you evaluating the success/failure of your cookie
code?

I ask because earlier in this thread you said:

>> That does not work either, it sets the cookie 
>> onto disk and instantly deletes it. 

are you using the existence of the cookie file in the OS to decide
if the cookie was set? I don't know one way or the other whether
that's a good indicator, and there's certainly better ways to
check.

My first check would of course be to redirect to a second script
that looks in the $_COOKIE (or $HTTP_COOKIE_VARS) array.
Unfortunately there's the faint possibility that the browser you're
using has been (unbeknownst to you) configured to silently discard
the cookies. Therefore I tend to look directly at the raw data
that's received by the browser from the cookie setting script.

If I execute the following one-liner:

  <?php setcookie("cname", "cdata", time()+3600, "/"); ?>

I get back the following header line in the reply:

  Set-Cookie: cname=cdata; expires=Sat, 06-Sep-03 01:30:36 GMT;
path=/

which is what I wanted; a non-session cookie that expires in an
hour.

If I execute this one-liner:

  <?php setcookie("cname", "cdata", 0, "/"); ?>

I get back the following header line in the reply:

  Set-Cookie: cname=cdata; path=/

which is, as far as I know, since it has NO expiration date, a true
session cookie.

If you haven't done so yet, I would strongly suggest you use telnet
or some other low level tool to examine the exact headers you're
getting back from the script.

Of course you may have gone through all of this already, in which
case sorry for wasting your time.

Good luck.

Pat Hunt

-------------------------

--Original Message Text---
From: Phil Powell
Date: Fri, 5 Sep 2003 19:24:59 -0400

<anger level="annoyed"> 

I tried setcookie('nordicnet_registration', $registrationNumber, 0,
'/'); // FAILED 

I tried header("Set-cookie:
nordicnet_registration=$registrationNumber; path=\"/\"\n"); //
FAILED 

Basically, every combination of setting a session cookie in PHP has
so far failed! 

I am now convinced that God does not want me to use sessions ever! 

</anger> 

Phil 
----- Original Message ----- 
From: Wellington Fan 
To: NYPHP Talk 
Sent: Thursday, September 04, 2003 6:40 PM
Subject: RE: [nycphp-talk] setcookie Pt. II


hahaha! serves me right for not reading THE VERY NEXT LINE: 
"The expire and secure arguments are integers and cannot be skipped
with an empty string. Use a zero (0) instead" 

so try this:
setcookie('nordicnet_registration', $uplinenumber, 0, "/" ); 
-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Phil Powell
Sent: Thursday, September 04, 2003 6:34 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] setcookie Pt. II


Yeah I tried that and got a parse error statement expected integer
on the setcookie() line. I guess when it says [int expire] they
MEAN int! :( 

Phil 
----- Original Message ----- 
From: Wellington Fan 
To: NYPHP Talk 
Sent: Thursday, September 04, 2003 6:28 PM
Subject: RE: [nycphp-talk] setcookie Pt. II


Phil, 

>From the setcookie page: 

You may also replace any argument with an empty string ("") in
order to skip that argument. 

the full signature (most of the parameters are optional ): 
setcookie ( name , value , expire, path , domain , secure ) 

your call: 
setcookie('nordicnet_registration', $uplinenumber, "", "/" ); 

Try that -- I'm guessing it will work. 

-- 
Wellington 

-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Phil Powell
Sent: Thursday, September 04, 2003 6:15 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] setcookie Pt. II


That does not work either, it sets the cookie onto disk and
instantly deletes it. 

Phil 
----- Original Message ----- 
From: Patrick Hunt 
To: NYPHP Talk 
Sent: Thursday, September 04, 2003 5:56 PM
Subject: Re: [nycphp-talk] setcookie Pt. II



set the expire time to zero.


--Original Message Text---
From: Phil Powell
Date: Thu, 4 Sep 2003 17:20:45 -0400

setcookie('nordicnet_registration', $uplinenumber); // SESSION
COOKIE TO BE SET 

I have this cookie I have to set that will be session-based (cookie
deletes when browser session is closed, the classic). However, the
cookie is set in /Main_page/registrering.php so the path for the
cookie is incorrect; I want the path to be '/'. HOWEVER, PHP is
strict on syntax so that if I set a path, I have to set a time int
value at the same time. 

I want to set the path and NOT the time int. How do I do that? 

Phil 






_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk






_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk






_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030905/c3895946/attachment.html>


More information about the talk mailing list