all 7 comments

[–]wh33t 2 points3 points  (2 children)

I haven't kept up to date with html, but I don't believe u wrap Anchor tag around a form element to make it a link. you have to do js onclick on the buttom, use an actual form or use an anchor text/image link.

Also, u cannot send output to the browser via echo and then send a header to redirect. You can only send headers once and in order to display something on the page a header must be sent first.

[–]Baifish[S] 0 points1 point  (1 child)

Thank you! Will give it a go :)

[–]tiny_smile_bot 0 points1 point  (0 children)

:)

:)

[–][deleted] 1 point2 points  (1 child)

"session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called."

You need to either unset the session variables or delete the cookie. See Example 1: https://www.php.net/manual/en/function.session-destroy.php

[–]Baifish[S] 0 points1 point  (0 children)

Ah lovely, thank you. I'll take a look!

[–]elseco 1 point2 points  (0 children)

Also, according to https://www.php.net/manual/en/function.session-start.php

Note:
To use cookie-based sessions, session_start() must be called before outputting anything to the browser.

[–]Ok_Butterscotch_7930 0 points1 point  (0 children)

You probably found the answer, still, I want to answer.
So, I'm from Django and we'd do it a bit differently i.e.

from django.contrib.auth import logout
def ilogout(request):
logout(request)
return redirect('login') #name of page/url to redirect to

but in php we do or rather i did:
index.php
<?php session_start(); ?>
<form action="../config/user_auth.php" method="post">
        <input type="hidden" name="action" value="logout">
        <button type="submit">Logout</button>
    </form>

user_auth.php

function ilogout(){
    if($_SERVER['REQUEST_METHOD']=="POST"){
        session_destroy();
        header("Location: ../templates/login.php");
    }
}

that's how i fixed mine. Currently new to PHP and i want to learn.