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

时间:2016-02-04 21:21:00

标签: php session cookies session-cookies

我应该将“陌生人”指定为会话cookie。我这样做了吗?我看到为cookie分配一个字符串并将一个值赋给变量同样的东西。

另外,如何在“陌生人”的同一行打印$_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>

1 个答案:

答案 0 :(得分:0)

根据您的评论,这是如何使其打印出您想要的方式。

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