setting cookies with $HTTP_POST_VARS[fname]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
guinness
Forum Newbie
Posts: 8
Joined: Tue Aug 05, 2003 1:59 pm
Location: VA

setting cookies with $HTTP_POST_VARS[fname]

Post 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!!
User avatar
guinness
Forum Newbie
Posts: 8
Joined: Tue Aug 05, 2003 1:59 pm
Location: VA

figured it out

Post 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.
Post Reply