Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在PHP中会话ID在会话间保持不变?_Php_Session_Sessionid - Fatal编程技术网

为什么在PHP中会话ID在会话间保持不变?

为什么在PHP中会话ID在会话间保持不变?,php,session,sessionid,Php,Session,Sessionid,考虑以下代码: <?php if (!session_id()) session_start(); echo session_id(); session_destroy(); ?> 它不会破坏你的会话ID 所以你就用 <?php session_start(); echo session_id(); session_destroy(); ?> 它不会破坏您的会话ID 所以你就用 <?php

考虑以下代码:

<?php
    if (!session_id())
        session_start();
    echo session_id();
    session_destroy();
?>

它不会破坏你的会话ID

所以你就用

<?php
    session_start();
    echo session_id();
    session_destroy();

?>

它不会破坏您的会话ID

所以你就用

<?php
    session_start();
    echo session_id();
    session_destroy();

?>

会话_destroy()销毁与当前会话关联的所有数据 会议它不会取消设置与关联的任何全局变量 或取消设置会话cookie。以使用会话变量 同样,必须调用session_start()

为了完全终止会话(如注销用户) 会话id也必须取消设置。如果使用cookie来传播 会话id(默认行为),则会话cookie必须为 删除。setcookie()可用于此目的

本手册附带一个代码示例:

示例#1使用$\u会话销毁会话

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?>
更新

所以。以下设置会导致相同的问题。当且仅当我将会话id作为请求参数时

重要提示: 此设置对会话劫持非常有用[]

会话_destroy()销毁与当前会话关联的所有数据 会议它不会取消设置与关联的任何全局变量 或取消设置会话cookie。以使用会话变量 同样,必须调用session_start()

为了完全终止会话(如注销用户) 会话id也必须取消设置。如果使用cookie来传播 会话id(默认行为),则会话cookie必须为 删除。setcookie()可用于此目的

本手册附带一个代码示例:

示例#1使用$\u会话销毁会话

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?>
更新

所以。以下设置会导致相同的问题。当且仅当我将会话id作为请求参数时

重要提示:
此设置对会话劫持非常有用[]

这实际上是OP描述的问题。即会话id持续存在。您的答案如何解决这个问题?它不会检查会话id是否存在。因为session_destroy不会取消设置您的session_id(),这无关紧要。在调用session_start之前,session_id()=''。这实际上是OP描述的问题。即session id持续存在。您的答案如何解决这个问题?它不会检查会话id是否存在。因为session_destroy不会取消设置您的session_id(),这无关紧要。session_id()=“”在调用session_start之前。@maggie-我尝试了这个,但没有成功-请查看上面我的问题编辑。我已经在测试服务器上测试了您的代码和手动代码示例。每次重新加载时都会有新的会话id。请参阅服务器详细信息above@maggie-我试过了,但没有成功-请看我上面的问题编辑。我已经在我的测试服务器上测试了你的代码和手动代码示例。每次重新加载时都会有新的会话id。请参阅上面的服务器详细信息
ini_set('session.auto_start', 'on');
ini_set('session.use_trans_sid', 'on');
ini_set('session.use_cookies', 'off');
ini_set('session.use_only_cookies', 'off');

if(!session_id())
  session_start();

echo session_id();
// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();