CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 PHP Cookies

Print topic Send  topic

Author Message
Rick
Posted: 04/18/2002, 7:36 AM

I'm using the following code snippet. I have no problems with creating the cookie, but can't get my php page to read the cookie the next time I visit the site. Anyone see what I'm doing wrong?

$nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1);
if (isset($cookieValue)){ // check to see if cookie exists
//cookie exists... get value
$value = $cookieValue;
}
else{ //cookie does not exists so set cookie and value to default
setcookie("cookieValue", "Default", $nextyear);
$value = "Default";
}
$tpl->set_var("value", $value);

Thanks,
Rick
Nicole
Posted: 04/19/2002, 1:16 AM

Rick,
as you know cookies must be sent before any other headers are sent. So you can put your code into page open event only. But you cannot use set_var function there, because template isn't loaded yet.
To verify cookie value use:
echo "cookie: ". $cookieValue. "<br>";
global $HTTP_COOKIE_VARS;
echo "cookie: ". $HTTP_COOKIE_VARS["cookieValue"]. "<br>";

It shouldn't be empty.
Rick
Posted: 04/23/2002, 8:08 AM

Thanks Nicole.
All is well in cookie land.
Rick

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.