php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #17158 setcookie()
Submitted: 2002-05-11 16:30 UTC Modified: 2003-01-09 03:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jtjohnston at courrier dot usherb dot ca Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.2.0 OS: n/a
Private report: No CVE-ID: None
 [2002-05-11 16:30 UTC] jtjohnston at courrier dot usherb dot ca
setcookie() states "cookies must be sent before any other headers are sent (this is a restriction of cookies, not PHP).

http://www.php.net/manual/en/function.setcookie.php

I would like to suggest this is a restriction of PHP, not cookies.

I can send and read cookies right in the middle of my HTML
when I use Javascript: http://www.collegeSherbrooke.qc.ca/languesmodernes/cookie.htm

<script>

setCookie("TestCookie","first time",expdate);
var DisplayData = getCookie("TestCookie");
document.write(DisplayData);

document.write("<br>");

setCookie("TestCookie","second time",expdate);
var DisplayData = getCookie("TestCookie");
document.write(DisplayData);

</script>

When can we expect a feature change on setcookie() ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-11 16:36 UTC] jan@php.net
this is because JS has dircet access to the browser., whereas PHP has not. it is a limitation of HTTP in general and cookies in particular. so the docs are right. no bug -> bogus
 [2002-05-11 16:37 UTC] edink@php.net
Javascript cookies are client-side which is an entirely different thing. If you want to get around header() and setcookie() limitations, take a look at http://www.php.net/manual/en/ref.outcontrol.php
 [2003-01-08 21:31 UTC] webmaster at fatal-instinct dot com
Exactly, PHP is server-side... So this is a restriction of the server-side theory. Javascript is a client-side browser controlled language, it is not executed on the server at all.
 [2003-01-09 00:56 UTC] jtjohnston at courrier dot usherb dot ca
Ok, but how many times do you have to press submit before the browser actually acts. Click #1 sets the cookie, click #2 is able to read the cookie change. 1 click too many in my opinion.
 [2003-01-09 03:16 UTC] philip@php.net
You only need one click.  set, click, read (tm).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC