Re: cookie problems...

From: Date: Wed, 04 Sep 2002 17:35:51 +0000
Subject: Re: cookie problems...
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-15678@lists.php.net to get a copy of this message
You can't set a cookie in a page and use it immediately. From the manual: "Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. " -- Best regards, George Nicolae IT Manager ___________________ PaginiWeb.com - Professional Web Design www.PaginiWeb.com "Nicholas Stuart" <nick@newtsplace.com> wrote in message news:2257.63.114.108.238.1031151383.squirrel@newtsplace.com... > Hello all, I seem to be having problems with getting cookies to set > correctly. I use the following code: > ___________________________________________________ > > header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); > header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); > header("Cache-Control: no-store, no-cache, must-revalidate"); > header("Cache-Control: post-check=1, pre-check=1", false); > header("Pragma: no-cache"); > > setcookie("User", $_POST['user']); > setcookie("FirstName", $row["first_name"]); > setcookie("LastName", $row["last_name"]); > setcookie("Ext", $row["EXT"]); > setcookie("Department", $row["dept"]); > > \\and to display it: > <TABLE border = 1> > <TR> > <TH>First Name:</TH> > <TH>Last Name:</TH> > <TH>Extension:</TH> > <TH>Department:</TH> > </TR> > <TR> > <TD><?=$_COOKIE['FirstName']?></TD> > <TD><?=$_COOKIE['LastName']?></TD> > <TD><?=$_COOKIE['Ext']?></TD> > <TD><?=$_COOKIE['Department']?></TD> > </TR> > </TABLE> > ___________________________________________________ > The problem it that the cookie does not set itself the first time the page > is loaded. It gives the following error: > Notice: Undefined index: FirstName in c:\inetpub\wwwroot\helpdesk\menu.php > on line 37 > Once you hit the reload button it works fine. > And if the cookie is set and the user logs back into the page with a > different user name then the old info is still set in the cookie until you > hit the reload button. > Thanks for the help! > -Nick > >

« previous php.windows (#15678) next »