How to create a cookie in wordpress

Cannot create cookie in single.php, how can I create it?

what i want to do

function totalView($  id){ $  count = 1; $  check = get_post_meta($  id, 'count',true); if(!$  check){     add_post_meta($  id,'count',$  count,true); }else{     $  inc = $  check+1;     $  a = update_post_meta($  id,'count',$  inc); } return 'Total views:&nbsp;<b>'.get_post_meta($  id, 'count',true).'</b> &nbsp; times'; } 

// single php reading

setcookie('read_'.$  post->ID, 'read' , 1);  if(!$  _COOKIE['read'.$  post->ID]){    totalView($  post->ID);    }