I think you could simplify much of what you are doing just by using the global $_SESSION
variable.
try something like this:
add_action('wp_head', 'your_session_variable' );
function your_session_variable(){
session_start();
$gender = isset($_GET['gender']) ? $_GET['gender'] : $_SESSION['gender'];
$_SESSION['gender'] = $gender;
}
Now to access the session variable from the template make sure to use session_start()
before grabbing the value from $_SESSION['gender']