Execute PHP function within onclick or href [duplicate]

1

I have a logoff system, and it works, but, I did not want to run it by using URL:

$logoff = filter_input(INPUT_GET, 'logoff', FILTER_VALIDATE_BOOLEAN);
if($logoff){
    unset($_SESSION['userlogin']);
    session_destroy();
    header('Location: ../painel');
}
<a href="painel.php?logoff=true">Sair</a>

Would there be any way to put a onclick , for example, within this <a> to execute a function in PHP? The same we do with javascript, for example:

<a href="javascript:void(0)">Sair</a>

Or do you guys think I could continue to log off like this?

I wanted to do, for example:

<a href="<?php echo minhaFuncao()?>">Sair</a>
    
asked by anonymous 14.12.2017 / 12:24

2 answers

0

Using javascript, the cool thing is that inside the function, you pass any file to redirect, including with parameters:

<a href="javascript:void(0)" onclick="redireciona('logoff.php');">Logoff</a>

<script>
    function redireciona(pagina) {
        var pagina;
        parent.location.href = pagina;
      return false;
    }
</script>
    
14.12.2017 / 12:46
0

I do not know if I understand your question very well.

But one thing you can do is call a JS function and inside it have a PHP function. This way you can have the PHP function you want to be called by a JS command.

    
14.12.2017 / 12:46