Cookie Not Working?

I have implemented the following piece of code so that I am able to capture the keyword phrase that someone uses to enter our website. The coding works in the sense that it will write the keyword on the page when I echo $sekeywords on the entry page but the cookie is not being carried over to any other pages. Could someone let me know if there is something wrong with this? I am using the cookie code above the html tag and before I call for the variable:

$parse = parse_url($_SERVER['HTTP_REFERER']);
$se = $parse["host"];
$raw_var = explode("&", $parse["query"] );
foreach ($raw_var as $one_var) {
    $raw = explode("=", $one_var);
    $var[$raw[0]] = urldecode ($raw[1]);
$se = explode (".", $se);
switch ($se[1]) {
    case 'yahoo':
        $sekeywords = $var['p'];
    case 'aol':
        $sekeywords = $var['query'];
        $sekeywords = $var['q'];
unset($parse, $se, $raw_var, $one_var, $var);
if (isset($_COOKIE['sekeywords'])) {
    $sekeywords = $_COOKIE['sekeywords'];
} else {
    $seexpire = time()+60*60*24*30*6;

I guess this is something that is not able to be fixed?

Does anyone have any ideas on what is wrong with the code?