cosi dovrebbe andare

codice:
<?php
session_start();
$key="keyword";
$redirect="http://www.domain.it/name.php";
$url=$_SERVER['HTTP_REFERER'];
$parsed_url=parse_url($url);
$query=$parsed_url[query];
$expla=explode("&",$query);
foreach ($expla as $valore) {
	$valore = strtolower($valore);
	if ((strlen($valore)>1)&&(substr_compare($valore, "q=", 0, 2)==0)){
		$ref_keyword_arr=explode("=",$valore);
		$ref_keyword=$ref_keyword_arr[1];
	}
}

if ((isset($ref_keyword))&&($key == $ref_keyword )) {
	$_SESSION=array();
	session_destroy();
	header("Location: $redirect");
} else {
	$_SESSION=array(); 
	session_destroy(); 
}
?>