如何将字符串分配给会话 cookie?

How to assign a string to a session cookie?

我应该将 "Hi stranger" 指定为会话 cookie。我这样做正确吗?我看到将字符串分配给 cookie 和将值分配给变量是一回事。

此外,如何在与 "Hi stranger" 相同的行中打印 $_SESSION['sess_var']

<?php
    $sess_thanksgiving = "Turkey, gobble gobble";
    $sess_christmas = "Santa Clause";
    session_start();
?>

<html>
    <head>
        <title></title>
    </head>
    <body>
        <?php
            $_SESSION['sess_var'] = "Hi stranger";
            $_SESSION['sess_christmas'] = "Santa Clause";
            $_SESSION['sess_thanksgiving'] = "Turkey, gobble gobble";

            echo "The session ID is ".session_id(); 
            echo "<br>Page 1 <br>";
            echo "The content of the session variable is " .$_SESSION['sess_var']."<br>";
            echo "Two or more elements were added to <br>";  
        ?>

        <a href="part2.php">Next Page</a>
    </body>
</html>

根据您的评论,这是按照您想要的方式打印出来的方法。

echo '$_SESSION[\'sess_var\'] 的内容是 ' . $_SESSION['sess_var'];