Anyone for cookies and milk? :-)

This is a discussion on Anyone for cookies and milk? :-) within the PHP General forums, part of the PHP Programming Forums category; Hey, Am just getting into PHP cookies and have gotten a problem...(surprise surprise) Am trying to set a basic ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-16-2003
Ryan A
 
Posts: n/a
Default Anyone for cookies and milk? :-)

Hey,
Am just getting into PHP cookies and have gotten a problem...(surprise
surprise)

Am trying to set a basic cookie to see exactly how things work before I
start using it in my apps, heres the code i am using:
(SetCookieEx.php)
<?php
setcookie("name1","1","","",".bestwebhosters.com") ;
setcookie("name2","1","","",".bestwebhosters.com") ;

echo "done";
?>

This is the output I am getting:
**********************
Warning: setcookie() expects parameter 3 to be long, string given in
/bestweb/public_html/testing/SetCookieEx.php on line 2

Warning: setcookie() expects parameter 3 to be long, string given in
/bestweb/public_html/testing/SetCookieEx.php on line 3
done

This is how I am trying to read the cookies: (ReadCookieEx.php)
****************************
<?php
if (isset($_COOKIE ['name1'])){
echo $_COOKIE ['name1'];
}else{echo "wrong1";}

if (isset($_COOKIE ['name2'])){
echo $_COOKIE ['name2'];
}else{echo "wrong2";}
?>

This is the output i am getting:
*******************
wrong1wrong2



Anybody have any ideas?

Cheers,
-Ryan

Reply With Quote
  #2 (permalink)  
Old 07-16-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Anyone for cookies and milk? :-)

--- Ryan A <ryan@jumac.com> wrote:
> Am just getting into PHP cookies and have gotten a problem...(surprise
> surprise)
>
> Am trying to set a basic cookie to see exactly how things work before I
> start using it in my apps, heres the code i am using:
> (SetCookieEx.php)
> <?php
> setcookie("name1","1","","",".bestwebhosters.com") ;
> setcookie("name2","1","","",".bestwebhosters.com") ;


I can never remember the attribute order for setcookie without looking it up,
and I prefer to just use header() to set my own Set-Cookie header. A simple
example for just testing things would go something like this:

header('Set-Cookie: foo=bar');

Hope that helps.

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
Reply With Quote
  #3 (permalink)  
Old 07-17-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Anyone for cookies and milk? :-)

Ryan A <ryan@jumac.com> wrote:
> Hey,
> Am just getting into PHP cookies and have gotten a problem...(surprise
> surprise)
>
> Am trying to set a basic cookie to see exactly how things work before I
> start using it in my apps, heres the code i am using:
> (SetCookieEx.php)
> <?php
> setcookie("name1","1","","",".bestwebhosters.com") ;
> setcookie("name2","1","","",".bestwebhosters.com") ;
>
> echo "done";
> ?>
>
> This is the output I am getting:
> **********************
> Warning: setcookie() expects parameter 3 to be long, string given in
> /bestweb/public_html/testing/SetCookieEx.php on line 2
>
> Warning: setcookie() expects parameter 3 to be long, string given in
> /bestweb/public_html/testing/SetCookieEx.php on line 3
> done

te>

<quote site=php>
bool setcookie ( string name [, string value [, int expire [, string
path [, string domain [, int secure]]]]])

[...]

All the arguments except the name argument are optional. You may also
replace an argument with an empty string ("")
</quote>

at first look this appears to be a bug. but I have a fealing its only
cause your error_reporting is set to E_ALL thus a warning is shown
because the third paramater should be a interger so change it to:

setcookie("name2","1",0,"",".bestwebhosters.com");

mabey documentation should be changed.

>
> This is how I am trying to read the cookies: (ReadCookieEx.php)
> ****************************
> <?php
> if (isset($_COOKIE ['name1'])){
> echo $_COOKIE ['name1'];
> }else{echo "wrong1";}
>
> if (isset($_COOKIE ['name2'])){
> echo $_COOKIE ['name2'];
> }else{echo "wrong2";}
> ?>
>
> This is the output i am getting:
> *******************
> wrong1wrong2


hmm..

few things:
1. is your setcookie returning true or false?
2. have you examined (or even see the cookie get set) the actual cookie
to see
3. good reading for intro to cookies for programmers:
http://wp.netscape.com/newsref/std/cookie_spec.html

>
>
>
> Anybody have any ideas?
>
> Cheers,
> -Ryan
>


Curt
--


Reply With Quote
  #4 (permalink)  
Old 07-17-2003
Nomadeous
 
Posts: n/a
Default Re: [PHP] Anyone for cookies and milk? :-)

From the official doc:
http://www.php.net/manual/en/function.setcookie.php
All the arguments except the name argument are optional. You may also
replace an argument with an empty string ("") in order to skip that
argument. Because the expire and secure arguments are integers, they cannot
be skipped with an empty string, use a zero (0) instead.
setcookie("name2","1",0,"",".bestwebhosters.com");
or
setcookie("name2","1",0,"",".bestwebhosters.com",0 ); ;-)

"Curt Zirzow" <curt@zirzow.dyndns.org> a écrit dans le message de news:
20030717053924.GA50106@bagend.shire...
> Ryan A <ryan@jumac.com> wrote:
> > Hey,
> > Am just getting into PHP cookies and have gotten a problem...(surprise
> > surprise)
> >
> > Am trying to set a basic cookie to see exactly how things work before I
> > start using it in my apps, heres the code i am using:
> > (SetCookieEx.php)
> > <?php
> > setcookie("name1","1","","",".bestwebhosters.com") ;
> > setcookie("name2","1","","",".bestwebhosters.com") ;
> >
> > echo "done";
> > ?>
> >
> > This is the output I am getting:
> > **********************
> > Warning: setcookie() expects parameter 3 to be long, string given in
> > /bestweb/public_html/testing/SetCookieEx.php on line 2
> >
> > Warning: setcookie() expects parameter 3 to be long, string given in
> > /bestweb/public_html/testing/SetCookieEx.php on line 3
> > done

> te>
>
> <quote site=php>
> bool setcookie ( string name [, string value [, int expire [, string
> path [, string domain [, int secure]]]]])
>
> [...]
>
> All the arguments except the name argument are optional. You may also
> replace an argument with an empty string ("")
> </quote>
>
> at first look this appears to be a bug. but I have a fealing its only
> cause your error_reporting is set to E_ALL thus a warning is shown
> because the third paramater should be a interger so change it to:
>
> setcookie("name2","1",0,"",".bestwebhosters.com");
>
> mabey documentation should be changed.
>
> >
> > This is how I am trying to read the cookies: (ReadCookieEx.php)
> > ****************************
> > <?php
> > if (isset($_COOKIE ['name1'])){
> > echo $_COOKIE ['name1'];
> > }else{echo "wrong1";}
> >
> > if (isset($_COOKIE ['name2'])){
> > echo $_COOKIE ['name2'];
> > }else{echo "wrong2";}
> > ?>
> >
> > This is the output i am getting:
> > *******************
> > wrong1wrong2

>
> hmm..
>
> few things:
> 1. is your setcookie returning true or false?
> 2. have you examined (or even see the cookie get set) the actual cookie
> to see
> 3. good reading for intro to cookies for programmers:
> http://wp.netscape.com/newsref/std/cookie_spec.html
>
> >
> >
> >
> > Anybody have any ideas?
> >
> > Cheers,
> > -Ryan
> >

>
> Curt
> --
>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:06 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0