2

I use Bootstrap in my application. After adding some design I started adding some functionality. I have a navbar with a dropdown, like here. On my Website, this also features a logout link:

<li><a href="/logout">Logout</a></li>

But my problem is, that my logout will only accept POST requests. So my simple question is: How can I make this a POST request instead of GET?

Thanks

LuMa
  • 1,333
  • 3
  • 13
  • 30
  • 1. Why does it only accept `POST`?, this doesn't really make sense. 2. you need to use a form to send `POST-requests` or you can use something like this http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit with an onclick – Dinistro Dec 08 '14 at 13:20
  • 3
    POST is [recommended](http://stackoverflow.com/q/3521290/167781) action for the logout. – Marko Dec 08 '14 at 13:25

3 Answers3

3

There is two ways to get it solved:

  1. Change your PHP side so it accepts $_GET request. (Tip: Use $_REQUEST to get value from $_GET or $_POST.

  2. Use jQuery/js for that (sorry, no js example).

    <a href="/logout" id="logout">Logout</a>

    // load jQuery first.
    $(document).ready(function(){
       $("#logout").click(function(){
          $.post($(this).attr("href"), function(){
              window.location = "www.example.com/login"; // or any other page after logging out.
          });
       });
    });
Justinas
  • 34,232
  • 3
  • 56
  • 78
  • Thanks, that worked for me :) I'm new with PHP/HTML/JS/jQuery... I think I need to take a closer look at JS/jQuery. THANKS! :) – LuMa Dec 08 '14 at 14:24
2

Use

<li><a href="/logout">Logout</a><form method="post" action="logout.php"><!--Whatever must be in your form--></form></li>

and

$("a + form").click(function(){
    $(this).next('form').submit();
});
bjb568
  • 9,826
  • 11
  • 45
  • 66
Mooseman
  • 18,150
  • 12
  • 67
  • 91
1

If you want POST request then you should use form

Example:

<form method='post' action='logout.php'>
    <input type='submit' value='Logout'>
    </form>
Prashant Tapase
  • 1,950
  • 2
  • 19
  • 31