PHP Smarty标签isset referer Session

i can't figure out what i am missing. My Plan: If the customer come from the Homepage with Products, it shall save the Link and the customer shall be able to get back to that point.

if the customer opens Link directly, he shall see a Link to the mainpage.

{php}
$go_back = htmlspecialchars($_SERVER['HTTP_REFERER']);
{/php}
{if $go_back|strpos:"https://kundencenter.example.org" === false}

$_SESSION['refererURL'] = $go_back;

{elseif isset($smarty.session.refererURL)}
<li id='Primary_Navbar-Account'><a href='".$_SESSION[refererURL]."'><i class='fa fa-home'></i> Homepage</a></li>
{else}
<li id='Primary_Navbar-Account'><a href='https://example.org'><i class='fa fa-home'></i> Homepage</a></li>
{/if}