Starting Session on Only One WordPress Page

I needed to start a session on a single WordPress page. The only good way to call a session is in the functions.php theme file like this:


function start_mywpsession() {
if (!session_id()) session_start();
}
add_action("init", "start_mywpsession", 1);

But this starts session on every page and I want to avoid that. Searching for solutions to this I can only find workable solutions in plugins.

Page slug and id are not available in the theme’s functions.php, so I did this:


function start_mywpsession() {
if (intval(strpos($_SERVER['REQUEST_URI'],"slug-i-want")) > 0) {
if (!session_id()) session_start();
}
}
add_action("init", "start_mywpsession", 1);