Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PHP COokies

0 views
Skip to first unread message

Shaun Williams

unread,
Aug 29, 2002, 2:44:32 AM8/29/02
to
Does anyone have a simple cookiescript that allows me to write a cookie and
then read it for auto logins.

Most I find are either too complicated, can't get then to work on php 4.2.x
(no globals) or they simply do not write a cookie under IIS/IE

Thanks in advance

Shaun Williams
www.eangulus.com


J.O. Aho

unread,
Aug 29, 2002, 3:33:53 AM8/29/02
to

Set a coockie:
$DomainName=".mydomain.com"; //for domains like www.mydomain.com
$value_I_want_save="This is my cookie!";
$lifetime_in_seconds=time()+3600 //set the cookie to live for 1h
setcookie("myCookie",$value_I_want_save,$lifetime_in_seconds,"/",$DomainName,0);


To read cookie:
if (!empty($_COOKIE)) {
extract($_COOKIE);
} else if (!empty($HTTP_COOKIE_VARS)) {
extract($HTTP_COOKIE_VARS);
}
echo $myCookie; //the output will be This is my cookie!


I hope it helps, should work under both Apache and IIS, with any cookie using
browser, and works even if global variables are sett off.

//Aho

Shaun Williams

unread,
Aug 29, 2002, 7:14:55 PM8/29/02
to
Sorry. Just tried it and again another cookie script that doesn't work.

No cookie is written and I do have cookies turned on.


"J.O. Aho" <us...@example.net> wrote in message
news:akkiut$1j048n$1...@ID-130698.news.dfncis.de...

Agelmar

unread,
Aug 29, 2002, 11:59:42 PM8/29/02
to
"Shaun Williams" <eang...@hotmail.com> schrieb:

> Sorry. Just tried it and again another cookie script that doesn't work.
>
> No cookie is written and I do have cookies turned on.
>

Enable display_errors in php.ini - you likely are generating an error, but
have error supression disabled... if I had to guess, I would say that you
are doing something that outputs info to the browser before you try to set
the cookie. (this could be a blank line or anything...)

Either way, the proper place for this is comp.lang.php - please post to
comp.lang.php, not alt.php.


Shaun Williams

unread,
Sep 2, 2002, 8:45:58 PM9/2/02
to
1. The code I have used that doesn't work on IIS has and does work without
modifictation on an Apache Server.

2. How on earth can you say this question doesn't belong here on alt.php?
Its a PHP question. Or does alt.php mean Alternatives to PHP???


"Agelmar" <ifetteNOs...@comcast.net> wrote in message
news:akmqjf$1kcrg3$1...@ID-30799.news.dfncis.de...

Jeff Donnici

unread,
Sep 2, 2002, 11:57:51 PM9/2/02
to
In article <aDTc9.9387$Dr5....@news-server.bigpond.net.au>,
eang...@hotmail.com says...

> 1. The code I have used that doesn't work on IIS has and does work without
> modifictation on an Apache Server.

Is it possibly a permissions issue? Have you turned on
display_errors to see what that provides?



> 2. How on earth can you say this question doesn't belong here on alt.php?
> Its a PHP question. Or does alt.php mean Alternatives to PHP???

Agelmar's on a mission to get people NOT to use this group and to
use comp.lang.php instead. This group's not going away anytime
soon, though, so use whichever you like. There are still plenty of
people here willing to help and learn. If you use both, though,
make sure to CROSS-POST (post to both at once) and not MULTI-POST
(post to both separately).

-- jeff

0 new messages