dsbifvcxr458755493 2016-05-03 13:16
浏览 36

在PHP中取消设置会话并使用onClick仅使用1个按钮提交表单

I need to submit a form and unset the session on submit at the same time on click.

This is currently my form and button :

<form method="post" action="" id="formID">
    //content here
    <button class="btn btn-success" type="submit" name="submit_req" value="submit_req" 
        onclick="submitForm('insert_man_order.php')">Submit Request</button>
</form>

This is my PHP for unsetting the session and resetting the value of my variable :

if(isset($_POST['submit_req'])){
    if(!empty($_SESSION['cart'])){
        foreach($_POST['quantity'] as $key => $val){
            $val == 0;
            unset($_SESSION['cart'][$key]);
        }
    }
}

JS :

function submitForm(action)
{
    document.getElementById('formID').action = action;
    document.getElementById('formID').submit();
}

The form submission is working but the session and $val are not unsetting/resetting. Any help will be appreaciated.

Thanks

  • 写回答

2条回答 默认 最新

  • dongwuwu6104 2016-05-03 13:24
    关注

    Use session_unset() to destory all session variables. If it doesn't work you can try below snippet to totally delete everything and start new.

    session_unset();
    session_destroy();
    session_write_close();
    setcookie(session_name(),'',0,'/');
    session_regenerate_id(true);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)