1

Does anyone know why my logout button isn't working? I have created a button in my HTML which looks like this:

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

And then I have a PHP file called logout.php which looks like this:

 <?php
session_start();

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

I don't know how to connect the two. If anyone could help me that would be great.

Andreas
  • 5,393
  • 9
  • 44
  • 53
SSS12_
  • 87
  • 1
  • 8

4 Answers4

4

You can call the PHP file using the bellow code.

As far as I know you can call an href directly from a button. Either you should use an anchor tag or a form to submit to particular a link. Here is the thread related to your query

<a href="your link..." class="btn btn-success">Logout</a>
Andreas
  • 5,393
  • 9
  • 44
  • 53
Vignesh
  • 355
  • 1
  • 4
  • 17
-1

It can not work on old php version. What is your PHP version? Or you may try session_unset() instead of session_destroy().

rubyshine72
  • 132
  • 1
  • 6
-1

There is anchor tag to redirect a page . But you want to use button then it can achieve by using javascript

  <button onclick="window.location.href='logout.php'">Logout</button>  
Nilesh Patil
  • 138
  • 1
  • 1
  • 10
-1

Change

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

To

 <button><a href="logout.php">Logout</a></button>
Arif.R
  • 1
  • 2