PDA

View Full Version : Cookie or Session Variable not being passed


neileisen207079
04-14-2009, 01:42 PM
I had this problem a few months ago and Jason called me - then after about an hour of messing around, I think he got it to work by making the cookie name all Caps. He couldnt understand why but marked it as fixed.

I hadnt used the tool since then but now am having the same problem. I simply want to pass the first name field on a form to either a session variable OR a cookie so that on the next page it can say "Thank you, [FIRST_NAME]."

I tried both a cookie and a session variabler and neither passes to the next page.

I used:
<?php
if (!session_id()) session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$_SESSION["FIRST_NAME"] = "".((isset($_POST["firstname"]))?$_POST["firstname"]:"") ."";
}
?>

to set the Server Variable FIRST_NAME from the form field firstname.

What am I doing wrong? I can use the ecart behavior of setting a session variable without actually having a cart on the site, right?

On the following page I am using

<?php echo $_SESSION['FIRST_NAME']; ?>

to show the variable, but it is always blank. For the cookie I used the behavior as well as the server behavior - tried setting it in both places and name it FIRST but it didnt work either.

Any ideas?

Ray Borduin
04-14-2009, 01:44 PM
you would need to add:

<?php
if (!session_id()) session_start();
?>

to the top of that page where you try to display it.

neileisen207079
04-14-2009, 01:54 PM
Thanks Ray, my new best friend! Is there something that adds that automatically or would you just have to know to do that manually any time you use session variables. I tried it and it worked perfectly by the way.. but I guess I am just thinking about for next time.

I also cant imagine I am the first person to have tried using the tool that makes the session variable only to not know how to retrieve it. Just wondering.

You are doing an amazing job staying on top of these forums... its really great to know someone is there when I need help!!! Thanks again.
Neil

neileisen207079
04-14-2009, 01:56 PM
Still cant figure out why the Cookie isnt working, but I guess this solves my problem without using cookies so I'll use it instead.

Ray Borduin
04-14-2009, 02:04 PM
It will automatically be added any time you use a server behavior that sets or uses session variables like ecart or dataassist or security assist, really almost all of our extensions will add it. If you aren't using any of our extensions or something else that adds it, then you have to do it manually.

It is something to keep in mind when using session variables in php.