setCSRF function - Removed code duplication.