相关疑难解决方法(0)

PHP中的session_unset()和session_destroy()有什么区别?

php.net文档:

session_destroy - 销毁注册到会话的所有数据

session_unset - 释放所有会话变量

我的三个部分问题是:

这两个功能看起来非常相似.
这两者之间究竟有什么区别?

两者似乎都删除了注册到会话的所有变量.它们中的任何一个实际上都会破坏会话本身吗 如果没有,你如何做到这一点(破坏会话本身).

这两个函数都没有删除客户端的会话cookie,这是正确的吗?

php session session-cookies

83
推荐指数
4
解决办法
6万
查看次数

注销要求再次单击两次

早上好。

构建Web应用程序来管理的汽车,你可以看到这个形象

您在上一张图片中看到的是文件index.php,该文件配置为显示用户是否登录的不同内容:

<body>
<div class="container">
    <h2>Welcome to the Automobiles Database</h2>
    <?php
if ( isset($_SESSION['error']) ) {
    echo('<p style="color: red;">'.htmlentities($_SESSION['error'])."</p>\n");
    unset($_SESSION['error']);
}
if ( isset($_SESSION['success']) ) {
    echo('<p style="color: green;">'.htmlentities($_SESSION['success'])."</p>\n");
    unset($_SESSION['success']);
}
?>


    <!-- without login -->
    <?php if(!isset($_SESSION['name'])) {
        echo '<p><a href="login.php">Please log in</a></p>';
        echo '<p>Attempt to <a href="add.php">add data</a> without logging in</p>';
    } ?>


    <!-- with login -->
    <?php if(isset($_SESSION['name'])) {
        echo '<table border="1"><thead><tr><th>Make</th><th>Model</th><th>Year</th><th>Mileage</th><th>Action</th></tr></thead>';
        $smtp = $pdo->query("SELECT autos_id, make, model, year, mileage FROM autos ORDER BY …
Run Code Online (Sandbox Code Playgroud)

php session

5
推荐指数
1
解决办法
95
查看次数

PHP 中 unset($_SESSION[])、session_unset() 和 session_destroy() 之间的区别

我需要有关 php 中的会话的帮助

我试过这段代码

<?php 
session_start();
$_SESSION['one'] = "Hello";
$_SESSION['two'] = "World";
$_SESSION['three'] = "Welcome to session";
var_dump($_SESSION);
Run Code Online (Sandbox Code Playgroud)

它打印

array (size=3)
  'one' => string 'Hello' (length=5)
  'two' => string 'World' (length=5)
  'three' => string 'Welcome to session' (length=18)
Run Code Online (Sandbox Code Playgroud)

然后我取消了会话一

unset($_SESSION['one']);
echo "Session one unset and only session two and three exist";
var_dump($_SESSION);
Run Code Online (Sandbox Code Playgroud)

它打印

Session one unset and only session two and three exist
array (size=2)
  'two' => string 'World' (length=5)
  'three' => string 'Welcome to session' (length=18)
Run Code Online (Sandbox Code Playgroud)

那么如果我销毁会话

session_destroy();
echo …
Run Code Online (Sandbox Code Playgroud)

php session

4
推荐指数
1
解决办法
6966
查看次数

标签 统计

php ×3

session ×3

session-cookies ×1