log out confirmation

Posted on 2009-02-22
Last Modified: 2012-06-21
Hello, I want a javascript that will give the user promt to confirm if he want to log out

here is the log out page code
<?php require_once("includes/functions.php"); ?>


		// Four steps to closing a session

		// (i.e. logging out)

		// 1. Find the session



		// 2. Unset all the session variables

		$_SESSION = array();


		// 3. Destroy the session cookie

		if(isset($_COOKIE[session_name()])) {

			setcookie(session_name(), '', time()-42000, '/');



		// 4. Destroy the session




Open in new window

Question by:MrFahad
    LVL 9

    Expert Comment

     this link will help you,
    LVL 8

    Expert Comment

    i think you need to change the logout button to look like the code attached .....

    and keep the logout.php code as it is

    <script type="text/javascript">
    function logconfirm() {
    var answer = confirm("Text or question you want to use");
    if (answer== true)
     } }
    <input type="button" onClick="logconfirm()" name="logout" value="logout">

    Open in new window

    LVL 107

    Accepted Solution

    @MrFahad: by the time you get to this script, it's too late!  A better place might be on the link to the logout script.  You can use the built-in window.confirm like this:

    HTH, ~Ray
    <a href="/logout.php" onClick="return confirm('Are you sure you want to Log Out');">Logout</a>

    Open in new window


    Author Closing Comment

    Thanks Ray, Great gay always give simple and easy answer yet very handy :D
    LVL 107

    Expert Comment

    by:Ray Paseur
    Thanks for your kind words and for the points!  Enjoy your project, ~Ray

    Author Comment

    your welcome ray, by the way please take a look at my problem here:


    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now