using session in wordpress to get template only once

Hi I am using session in wordpress to get template part in the session. I am new to php and don’t know how to fix.

Using below code to pull the template part once and use only the first one for the session.
It pulls only once but when I refresh the page it returns blank
How can I fix it?

            session_start(); 
            if(!isset($_SESSION['function_ran'])){ 
            // get_empplate_part
            $_SESSION['function_ran'] = true; 
            } 


Source: stackoverflow-php