Skip to content Skip to sidebar Skip to footer

How To Cause The Confirm Alert Before Logout

I want to popup the confirm alert message before I logout of my account. But it doesn't popup and I am not sure whether i put the echo at the right line.

Solution 1:

You have to put that confirmation on the view not controller.

Let's say you have a logout button:

Html:

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

Js (jquery):

$(function(){
    $('a#logout').click(function(){
        if(confirm('Are you sure to logout')) {
            returntrue;
        }

        returnfalse;
    });
});

Php

<?php// Your logout functions...

Solution 2:

You need an html link in the first place

<a href="logout.php" onclick=" return confirm("Are You sure you want to logout?");">Logout</a>

Then in your logout.php, you should have

<?php
session_start();
session_destroy();
header('the_page_you_wish.php');

Post a Comment for "How To Cause The Confirm Alert Before Logout"