将html中的注销按钮链接到注销php

将html中的注销按钮链接到注销php,php,Php,有人知道为什么我的注销按钮不起作用吗?我在HTML中创建了一个按钮,如下所示: <button href="logout.php">Logout </button> <?php session_start(); if(session_destroy()) { header("Location: index.html"); } ?> 注销 然后我有一个名为logout.PHP的PHP文件,它如下所示: &l

有人知道为什么我的注销按钮不起作用吗?我在HTML中创建了一个按钮,如下所示:

<button  href="logout.php">Logout </button>
 <?php
session_start();

if(session_destroy()) {
  header("Location: index.html");
}
?>
注销
然后我有一个名为logout.PHP的PHP文件,它如下所示:

<button  href="logout.php">Logout </button>
 <?php
session_start();

if(session_destroy()) {
  header("Location: index.html");
}
?>


我不知道如何把两者联系起来。如果有人能帮助我,那就太好了。

您可以使用下面的代码调用PHP文件

据我所知,您可以通过按钮直接调用href。您应该使用锚定标记或表单提交到特定链接。


它不能在旧的php版本上工作。 你的PHP版本是什么?
或者您可以尝试使用session_unset()而不是session_destroy()。

有锚定标记用于重定向页面。但您需要使用按钮,然后它可以通过使用javascript实现

  <button onclick="window.location.href='logout.php'">Logout</button>  
注销
更改

 <button  href="logout.php">Logout </button>
注销



发生了什么?我知道,
没有使用
href
。这非常有效,谢谢!)将在10分钟后将其标记为正确