简体   繁体   English

session_destroy()不适用于服务器上的PHP> 7.0

[英]session_destroy() doesn't work with PHP >7.0 on server

I'm new to stackoverflow but I'm not new to PHP. 我是stackoverflow的新手,但不是PHP的新手。 Now I've a funny problem: 现在我有一个有趣的问题:

I'm developing with XAMPP 7.1.11 with PHP 7.1.11 locally, doing logging out from sessions with 我正在使用XAMPP 7.1.11和PHP 7.1.11在本地进行开发,并通过

$_SESSION = array();
session_destroy();  

in a logout.php file. 在logout.php文件中。 On top of the page there's a 页面顶部有一个

session_start();

and in past everything went without any problem. 过去一切都没有问题。 Now I did a php version change at the provider from PHP 7.0 to 7.1 and it's not possible to log out any more, the session informations seem not be deleted. 现在,我在提供程序中将php版本从PHP 7.0更改为7.1,并且无法注销,会话信息似乎没有被删除。 I searched the internet but I didn't find a helpful hint and the provider told me to ask some PHP forums. 我在互联网上搜索,但是没有找到有用的提示,提供程序告诉我询问一些PHP论坛。

I tried all hints in the topics 我尝试了主题中的所有提示

why session_destroy() not working 为什么session_destroy()不起作用

The session_destroy(); session_destroy(); doesn't work correctly on server with php 5.3.21 在带有PHP 5.3.21的服务器上无法正常工作

and many more but nothing is working. 还有更多,但没有任何效果。 A Change from PHP 7.0 to PHP 7.2 at the provider doesn't help as well. 提供程序将PHP 7.0更改为PHP 7.2也无济于事。

What I'm doing wrong? 我做错了什么? as I said: locally everything works normally. 正如我所说:在本地,一切正常。

Thanks for your help! 谢谢你的帮助!

Here's the complete logout.php file: 这是完整的logout.php文件:

<?php
session_start();
?>
<!-- Import Wordpress -->
<?php 
define('WP_USE_THEMES', false);
require('../wp-load.php'); ?>
<?php get_header(); ?>
<link href="cpplattform.css" type="text/css" rel="stylesheet">
<div class="spacer"></div>
<div class="container">
    <div class="row">
        <div class="<?php if ( is_active_sidebar( 'rightbar' ) ) : ?>col-md-8<?php else : ?>col-md-12<?php endif; ?>">
            <div class="content">                   
                <h2 class="entry-title">Logout</h2>
                <!----------------------------------------------------->                
                <section class = "conf">    
                    <i class='fa fa-power-off fa-5x' style ='color:#00ADED'></i>
                    <br>
                    <br>
                    Your logout was successful! Good Bye!
                    <br>
                    <br>
                    <a class="btn btn-md btn-inverse" href="cplogin.php">Login again</a></p>
                    <?php

                        $_SESSION = array();
                        $_SESSION['username'] = "";                     
                        session_destroy();                      
                    ?>                  
                </section>              
                <!----------------------------------------------------->
            </div><!--content-->
        </div>
    </div>
</div>

<!-- Change all links from Wordpress -->
<script src="cplinkmodify.js"></script>
<?php get_footer(); ?>

I added some static pages and imported a Wordpress theme. 我添加了一些静态页面并导入了Wordpress主题。

Note: You do not have to call session_destroy() from usual code. 注意:您不必从常规代码中调用session_destroy()。 Cleanup $_SESSION array rather than destroying session data. 清理$ _SESSION数组而不是破坏会话数据。

Show us your code page where you set $_SESSION = array(); 向我们展示您的代码页,其中您设置了$_SESSION = array(); This should be all you need to do. 这应该是您需要做的所有事情。 Check you have set session_start(); 检查您是否设置了session_start(); on this page: 页面上:

session_start();
$_SESSION = []; //empty the array. 

--End of file.

If you want to make absolutely sure that it works ok you can try using something like this: 如果您想绝对确定它可以正常工作,则可以尝试使用以下方法:

session_start();
$_SESSION = []; //empty array. 
session_write_close(); 

But note any further edits to any session data on this script will not be saved once the script completes. 但是请注意,脚本完成后,将不会保存对该脚本上任何会话数据的任何进一步编辑。


You may also have an issue if your scripts are in different folders and the local php.ini session name is different in these different folders... Different names, different sessions. 如果您的脚本位于不同的文件夹中,并且本地 php.ini会话名称在这些不同的文件夹中不同,则您可能还会遇到问题。不同的名称,不同的会话。

Central PHP.ini: 中央PHP.ini:

 session.name=somethingSessiony 

local folder specific PHP.ini 本地文件夹特定的PHP.ini

 session.name=somethingsessiony 

If you feel this may be a factor try something like this: 如果您认为这可能是一个因素,请尝试以下操作:

error_log(__FILE__." : " .print_r(session_name(),true)); 

In both the file that clears the session data and the file that should be reading the "empty" session data. 在清除会话数据的文件和应读取“空”会话数据的文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM