drrw8672 2018-01-19 07:27
浏览 69

php session破坏特定服务器中的问题

I am creating 3 sessions and destroying with proper functions. However it throws weird issue to me where in Internet explorer, it doesn't destroy session, in firefox and chrome, I have to refresh the page twice. Here is the simple code I am using to check:

login.php (This is to create sessions)

if(isset($_POST['create_session'])){
$_SESSION['user_id'] = '1';
$_SESSION['first_name'] = 'first name';
$_SESSION['last_name'] = 'last name';

echo "Session Created Successfully! Click <a href='index.php'>here</a>";
}

?>


<form method="post" action="">
    <input type="submit" value="Create Session" name="create_session">
</form>

index.php (This is to check whether session has been created properly or not)

<?php
session_start();

echo "<pre>";print_r($_SESSION);

echo "<a href='logout.php'>logout</a>";    

?>

logout.php (This is how I destroy the session)

<?php

session_start();
session_destroy();
session_write_close();    
header("location:login.php");

?>

Functions I have tried with referring stackoverlow itself are as blow:

  1. session_cache_limiter("nocache");
  2. session_cache_expire(0);
  3. session_write_close();
  4. ob_flush();

However none of the solution worked.

I am using cloudsites from liquid web to host above code, in case any one has faced same issue from same service provider. Their support says they use opcache engine in cloud, in case opcache is the reason, not sure about that.

It's a deadlock for me to host a project, so right solution will be really helpful.

  • 写回答

2条回答 默认 最新

  • douzhan1935 2018-01-19 07:30
    关注

    try this please:

    <?php
        session_start();
        session_unset();
        $_SESSION = array();
        session_destroy();
        header("Location: http://example.com");
    
    ?>
    

    This should be enough to solve your problem.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法