php 如何一键销毁php会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3113223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:43:26  来源:igfitidea点击:

How to destroy the php session with one button

phphtmlsessionlogoutdestroy

提问by tom

I'd like to make a simple form button which completely destroys the session when you click on it. I am just starting to use PHP for the first time, and do not see how I implement it into my HTML code.

我想做一个简单的表单按钮,当你点击它时它会完全破坏会话。我刚刚开始第一次使用 PHP,并没有看到我如何将它实现到我的 HTML 代码中。

What I'd like is simply a form button which will clear the session (and possibly an explanation as to how it works)

我想要的只是一个可以清除会话的表单按钮(可能还有关于它如何工作的解释)

回答by Caladain

The form button is just like any other form button, nothing special. Catch the POST on the php side of things, and use session_destroy(); to kill the session data entirely.

表单按钮就像任何其他表单按钮一样,没有什么特别之处。捕获 php 端的 POST,并使用 session_destroy(); 完全杀死会话数据。

See this guide for info about forms and post if you're hazy on the subject: http://www.tizag.com/phpT/postget.phpand this http://www.tizag.com/phpT/phpsessions.phpfor info about sessions

如果您对这个主题感到模糊,请参阅本指南以获取有关表单和帖子的信息:http: //www.tizag.com/phpT/postget.phphttp://www.tizag.com/phpT/phpsessions.php有关会话的信息

More info about forms and PHP and how to work with the data from the form: http://www.tizag.com/phpT/forms.php

有关表单和 PHP 以及如何使用表单中的数据的更多信息:http: //www.tizag.com/phpT/forms.php

Example:

例子:

Order.html:

订单.html:

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post">
<input type="submit" />
</form>
</body></html>

process.php:

进程.php:

<html><body>
<?php
session_destroy();
?>
</body></html>

It's cheesy...does this help?

这很俗气……这有帮助吗?