You are here: Re: setcookie issue « PHP Programming Language « IT news, forums, messages
Re: setcookie issue

Posted by Andy Hassall on 10/08/06 19:53

On Sun, 8 Oct 2006 14:19:38 -0500, "GregoryD" <deergregoryd@gmail.com> wrote:

>I'm going to try to simplify this issue as much as possible.
>
>In my public_html/ directory, I have a login script that sets a cookie to be
>used for authentication purposes. To set the cookie, it has something like
>this:
>
><?php
>setcookie('code',$value, time + $lifetime, '/', '.example.com');
>?>

That would raise a warning "use of undefined constant 'time', assumed string"
if you have PHP error reporting set to a sensible level, and your expiry time
is likely to be way in the past - "time" should be "time()". But that might
just be a typo in your post.

>This, to my knowledge, is supposed to set a cookie named code with a value
>of $value and an expiration date of time + $lifetime. Additionally, it is
>to be read in public_html and all subdirectories over the entire domain of
>*.example.com
>
>Yet if I'm trying to get the value of the cookie, as in:
>
><?php
> $cookie = $_COOKIE['code'];
> echo $cookie;
>?>
>
>in a subdirectory, say public_html/auth/, the result of the second script is
>nothing. If I put that same script in the public_html/ directory, it'll
>print out my $value.
>
>I'm using php 4.3
>
>Any thoughts?

Does the browser already have a more specific cookie set with the same name
but for the /auth directory? If so, your first setcookie won't override it, and
this other cookie will be the one that's read.

Try clearing all cookies for the domain and trying again, and also using a
cookie viewer tool to see what you actually have set (e.g.
http://addneditcookies.mozdev.org/) and/or an HTTP headers viewer to see what
cookies the browser is really sending (http://livehttpheaders.mozdev.org/ or
http://www.fiddlertool.com/fiddler/).

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация