Firstly, I am starting a new thread because I would like to get some new eyes on this problem. I have another thread going, but it is getting long, drawn out and hard to read. With that said, here is my problem:
When I try to set a cookie with this code:
PHP Code:
setcookie ("please", "work");
It works. I get the cookie named please, with a value of work.
Notice the quotes around $_POST['email']. When I did that, I got this error returned:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/t/r/e/trevzilla/html/getfile.php on line 4
So, for giggles, I changed the single/double quotes around to this:
Variables are not interpolated within single quotes, so you are setting $email to the literal string value '$_POST["email"]', not the value of the post variable. (The '%24_POST%5B%22email%22%5D' you see is just the urlencoded value, which is how the strings have certain characters "escaped".)
You should not have to quote the variables at all when all you want is the value of the variable. The unexpected T_ENCAPSED_AND_WHITESPACE error is because of a quirk in PHP: associative array indexes for an array variable being used within a double-quoted string must not be quoted. What makes this confusing is that when not within a double-quoted string, they need to be quoted. But again, there's no reason to be quoting it in this example.
Assuming you're positive the email value is populated, all I can think is that there's something about it that messes up the urlencoding. If using PHP 5, see what happens with this:
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Very nice! One step closer! So I tried that with one cookie named 'email' and sure enough it worked. So, after taking one or two victory laps around my room, I sat back down to do some copying and pasting to get that code to work with the second cookie I need to set. 'name' to be specific.
As you can see, I'm using PHP 4 still. Well, when I ran that code, I only got one cookie created, and that was of the 'name' variety. It seemed to skip over 'email' entirely. Hopefully this is an easy fix, but I sure don't see what to do. Thanks for any help!
Forgot about that: you need to tell header() not to replace headers of the same type (which is the default behavior), so add a false for the optional 2nd parameter:
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks