views:

43

answers:

3

so i need a cookie set for 21 days on a browser when a user hits the site and everytime the user returns in that 21 day period i need to retrieve that value

if($_REQUEST['ref'] == "something"){
  setcookie('something_value', "something" ,time()+60*60*24*21,'/','mydomain.com');
}

in the view

<?php if(isset($_COOKIE['something'])) { ?>

but when i view the cookies in safari and firefox i dont see "something"

am I missing something

+4  A: 

Looks like you've swapped the first two parameters of setcookie. The first parameter should be the name of the cookie.

@Jeff, nice one! I would also recommend John to put a . in front of the domain name. But it's pretty obvious that the Cookie_name and Cookie_value where switched.
Frankie
@Frankie, the dot will make the cookie available to subdomains, so it wouldn't be a bad idea to make it a habit. Nice call.
Awesome guys thanks, that fixed the problem and the . is a great idea as well
Matt
A: 
// prefix the mydomain.com with a . (makes it work on more browsers)
setcookie('something_value', "something" ,time()+60*60*24*21,'/','.mydomain.com');

I've also had that problem and putting a . in front of the domain name made wonders for me.

Frankie
A: 
  1. Do not view cookies in safari and firefox. Cookie is an HTTP header and nothing else. Do not rely on inner browser's mechanism. But rely on HTTP log only. Do you see your cookie in HTTP log?
  2. what is it's name? "something_value"? Don't you mess something? ;)
Col. Shrapnel