get_query_var('cat');
only returns the category id in a category archive page;
in a single post, try to use, for instance:
wp_get_post_categories()
example:
if( in_array(4, wp_get_post_categories($post->ID)) ) :
http://codex.wordpress.org/Function_Reference/wp_get_post_categories