Page 1 of 1

setting cookies with $HTTP_POST_VARS[fname]

Posted: Tue Aug 05, 2003 1:59 pm
by guinness
I'm trying to set some cookies for my users and I'm having a tough time getting it to work. I know the setcookie() method needs to be called before anything else on the page so I've pretty much designed it that way. Here's what doesn't work:

<?
require "/utilities/SiteUtilities.class";
$page = new SiteUtilities;
session_start();
$expiry = 60*60*24*100;
session_set_cookie_params ($expiry,"",".domain.com",0);
$isFnameSet = setcookie ("fname",$HTTP_POST_VARS[fname],$expiry,"/",".domain.com",0);
?>

Here's what does work:

<?
require "/utilities/SiteUtilities.class";
$page = new SiteUtilities;
session_start();
$expiry = 60*60*24*100;
session_set_cookie_params ($expiry,"",".domain.com",0);
$isFnameSet = setcookie ("fname","john",$expiry,"/",".domain.com",0);
?>

So I believe by process of elimination that $HTTP_POST_VARS[fname] is causing the problem. I have to be able to use this because the info is coming from the previous page. Anyone got a solution?

Thanks!!

figured it out

Posted: Tue Aug 05, 2003 2:43 pm
by guinness
Instead of passing fname like $HTTP_POST_VARS["fname"] from the previous page, I passed it as $_SESSION["fname"] and avoided the form altogether. I have the first page POST to itself if it passes validation. It says "Please confirm you info". At that point I stick the info into the session and instead of having it passed to the next page via a form, I just have a link to the thx page where the setcookie() method calls the info from the session. It works.