Hi!
I recently migrated my site, www.tubespot.com, over to Drupal. I show TV commercials (including all the Super Bowl commercials) and I want to set a cookie so that when a user chooses a video format--either WMV or Quicktime--my site will remember their preference.
Right now, if you look at a video, there's a link at the bottom to change to WMV. What that does is go to another node that issues a setcookie command:
setcookie ('videopref', '2');
It seemst to work with Firefox, but it doesn't always set the cookie with IE. I'm guessing the reason is that setcookie() is supposed to be run before any other content is sent to the web browser, right? Because it's supposed to be in the header?
So how do I handle that in Drupal? It seems I can't just put the setcookie() command in the content of a node, becuase no matter what the browser will get other data before it gets to the setcookie command.
I'm sure this is a pretty common problem, but my searches didn't reveal any results.
Thanks!
Chris
tubespot.com
Comments
Well, in fact I'm new to
Well, in fact I'm new to drupal as well but I guess
http://drupaldocs.org/api/head/function/drupal_page_header
might help you.
A little over my head
Hmm, that function is a little over my head. I undertsand the concpept of what it does, but can anyone walk me through how I would use php's setcookie() with it?
I did not have a try within
I did not have a try within drupal but - you should create the needed http cookie header part on your own (unsing the mentioned drupal header method) as setcookie() does not care about the current header situation.
example:
Set-Cookie: foo="bar"; expires=Tue, 29-Mar-2006 19:30:42 GMT; Max-Age=2592000; Path=/; Version="1";Unclear
This is a bit unclear for me. Anybody has a snippet?
Thanks
FnL
snippet
better late than never :)
using sess_read/sess_write is bad since they're internal functions but "stackoverflow example - setting a cookie" is fine.
you can also save variables in the session by pasting
$_SESSION['your-variable'] = 'your-value';in template.php and access it from your .tpl files withecho $_SESSION['your-variable'];-
silence != inaction