note 71743 modified in function.setcookie by danbrown

From: Date: Sun, 17 May 2009 17:56:15 +0000
Subject: note 71743 modified in function.setcookie by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155040@lists.php.net to get a copy of this message
When setting a top level domain ex ".mydomain.com" you must add the secure arg so it should look like <?php setcookie("TestCookie", $value, time()+3600, "/", ".example.com", 0); ?> ignoring the secure arg makes IE ignores the cookie to get the top level domain use <?php $myDomain = ereg_replace('^[^\.]*\.([^\.]*)\.(.*)$', '\1.\2',$_SERVER['HTTP_HOST']); ?> to avoid localhost switch use <?php $phpCkDmn = $_SERVER['HTTP_HOST'] != "localhost" ? $myDomain : false; ?> --was-- When setting a top level domain ex ".mydomain.com" you must add the secure arg so it should look like setcookie("TestCookie", $value, time()+3600, "/", ".example.com", 0); ignoring the secure arg makes IE ignores the cookie to get the top level domain use $myDomain = ereg_replace('^[^\.]*\.([^\.]*)\.(.*)$', '\1.\2',$_SERVER['HTTP_HOST']); to avoid localhost switch use $phpCkDmn = $_SERVER['HTTP_HOST'] != "localhost" ? $myDomain : false; http://php.net/manual/en/function.setcookie.php

« previous php.notes (#155040) next »