php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22013 setcookie does not work on Mozilla with localhost as domain
Submitted: 2003-02-02 12:35 UTC Modified: 2003-02-03 03:19 UTC
From: frankkim at attbi dot com Assigned:
Status: Not a bug Package: HTTP related
PHP Version: 4.3.0 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: frankkim at attbi dot com
New email:
PHP Version: OS:

 

 [2003-02-02 12:35 UTC] frankkim at attbi dot com
Today I upgraded from PHP 4.2.2 to PHP 4.3.  I am using Apache 2.0.43 on Windows with PHP CGI.

After doing this upgrade, setcookie() stopped working for me using Mozilla 1.3a though it continued to work using IE.  setcookie() was working for me with both browsers before the upgrade.

Here is a script that illustrates the bug.

<?php

define('ID', 'id');
define('USERNAME', 'username');

// save the login information into the cookie which will expire in 30
// days
$expirationTime = time()+60*60*24*30;
$domain = $_SERVER['HTTP_HOST'];
$success = true;
if (!setCookie(ID, $this->id, $expirationTime, '/', $domain, 0)) {
  $success = false;
}
if (!setCookie(USERNAME, $this->username, $expirationTime, '/', $domain, 0)) {
  $success = false;
}

if ($success) {
  print "setCookie's succeeded";
} else {
  print "setCookie's failed";
}

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-02 12:57 UTC] msopacua@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


your script contains errors: $this is not an object.

Add:
error_reporting(E_ALL);

in line 1 to see if there's anything else reported.

 [2003-02-02 13:15 UTC] frankkim at attbi dot com
I added:

error_reporting(E_ALL);

to the script and saw no errors reported.

This was not surprising since I have this set in php.ini:

error_reporting  = E_ALL; display all errors, warnings and notices
display_errors = On
 [2003-02-02 13:16 UTC] frankkim at attbi dot com
By the way, my original test script was kind of stupid.  Here is the corrected test script.

<?php

error_reporting(E_ALL);

define('ID', 'id');
define('USERNAME', 'username');

// save the login information into the cookie which will expire in 30
// days
$expirationTime = time()+60*60*24*30;
$domain = $_SERVER['HTTP_HOST'];
$success = true;
if (!setCookie(ID, '1', $expirationTime, '/', $domain, 0)) {
  $success = false;
}
if (!setCookie(USERNAME, 'frankkim', $expirationTime, '/', $domain, 0)) {
  $success = false;
}

if ($success) {
  print "setCookie's succeeded";
} else {
  print "setCookie's failed";
}

?>
 [2003-02-02 13:38 UTC] philip@php.net
Please confirm that HTTP_HOST exists (i.e. what $domain is)
 [2003-02-02 13:48 UTC] frankkim at attbi dot com
$domain is 'localhost' because I am testing on my local
machine.

I updated the script to not pass the $domain and $expirationTime to the setCookie function and the script now works.

I am not sure why 'localhost' would be a problem since I see when I take out $domain and $expirationTime, Mozilla sets
the host for the cookie to 'localhost'.  Maybe this is a Mozilla bug.
 [2003-02-02 15:18 UTC] philip@php.net
According to the spec:
http://wp.netscape.com/newsref/std/cookie_spec.html

The domain must have at least two periods.  I'm not sure how this applies to localhost but I guess for localhost just don't set it or set as an empty string.




 [2003-02-03 03:19 UTC] sniper@php.net
It can't really be PHP bug..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC