FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » setcookie() Expiration
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: setcookie() Expiration [message #171071 is a reply to message #171070] Wed, 22 December 2010 16:10 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
Tyrone Slothrop wrote:
> On Wed, 22 Dec 2010 09:30:46 +0100, "Álvaro G. Vicario"
> <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> wrote:
>
>> El 22/12/2010 0:45, Tyrone Slothrop escribió/wrote:
>>> I am having problems setting a cookie to expire in the future rather
>>> than at end of session on a particular server. I can upload the code
>>> to another server and the cookie expiration is correct. I checked the
>>> server time and it is correct.
>>>
>>> I have even tried simplifying the code to essentials and it will not
>>> work.
>>> setcookie ('cookie_name', 'cookie_value', time()+(60*60*24*7));
>>>
>>> What is even more frustrating is that code I wrote years ago which
>>> used to work, now does not. I have tried in multiple browsers and all
>>> have the same problem. This pretty much narrows it down to the
>>> server.
>>>
>>> This is a leased server running CentOS and cPanel and all updates to
>>> PHP, etc. are current within a month or two. I have root access.
>>>
>>> Anyone else run into this problem?
>> The first step is to inspect the output of setcookie(). You can see the
>> raw HTTP header with many tools, such as the Firebug extension for
>> Firefox, but most browsers have a builtin cookie manager as well.
>>
>> Also, make sure you are using a valid domain name for your tests.
>
> Let's assume that I pretty much know what I am doing. I have been
> coding PHP for at least 12 years, developing backends for complex web
> sites. Not to say I don't make mistakes - and I make some incredibly
> silly ones at times - but I have verified the code on a different
> server and I know it works.
>
> The test methodology I created is a standalone script which creates
> three cookies, passing various parameters from the simple:
> setcookie(name, value, expiration)
> to the more complex:
> setcookie(name, value, expiration, path, domain)
>
> I primarily use Firefox because of Firebug and developer's extension.
> Developer's extension installed for IE, as well as HTTP Analyzer.
>
> In all cases the cookies are set properly but the expiration on the
> server which will host the scripts refuses to set a cookie which
> expires beyond the life of the session. On the second server and
> using the same browser, the same script works properly with the cookie
> expiration set a few days in the future.
>
> It appears the next test is to set these cookies using JS to make
> absolutely sure it is not the browser but, in the context of the
> application I am developing, using JS is not the preferred option. The
> script accepts post data from a remote server, processes the data,
> sets cookies to prevent duplicate submissions, then redirects to
> another form for further processing. The cookies set are encrypted
> (64 alphanumeric characters). Upon a second submission the cookies
> are decrypted, the the data is compared against existing records in
> data table, and, should there be a match, immediately redirects to
> the next form. The header function will not allow me to write
> anything to output prior to redirection so JS cookies cannot be
> written, at least prior to the header() call. Anyway, I know the test
> script in using even the simplest cookies behaves on another server.
>
> This thing has me totally baffled.

Are you sure the server is running the code you think it is?

I had intense incrustations on several occasions that turned out to be a
simple problem that either the browser had cached an old copy and
wouldn't refresh it, or the code had ended up somewhere else on the
server. Deep embarrassment, but shit happens.

Incidentally, the problem of embedded images served by php pages was
solved for development by adding a dummy argument with a random value
that fools IE into thinking its a different image. Which it may, or may
not, be.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: The Future of PHP
Next Topic: what all languages i want to learn to make a social networking site?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Oct 18 14:23:10 GMT 2024

Total time taken to generate the page: 0.09597 seconds